rogue4: prevent segfault on getpwuid failure
This commit is contained in:
parent
ab5d57406c
commit
3f546ef2eb
2 changed files with 15 additions and 6 deletions
|
|
@ -120,7 +120,8 @@ setup()
|
|||
#ifdef SIGBUS
|
||||
signal(SIGBUS, auto_save);
|
||||
#endif
|
||||
signal(SIGSEGV, auto_save);
|
||||
/* Don't bother saving a game that segfaulted. */
|
||||
signal(SIGSEGV, SIG_DFL);
|
||||
#ifdef SIGSYS
|
||||
signal(SIGSYS, auto_save);
|
||||
#endif
|
||||
|
|
|
|||
|
|
@ -53,6 +53,7 @@ char *strdup(const char *s);
|
|||
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <errno.h>
|
||||
|
||||
#if defined(_WIN32) && !defined(__MINGW32__)
|
||||
#define PATH_MAX MAX_PATH
|
||||
|
|
@ -265,8 +266,10 @@ md_getusername(int uid)
|
|||
struct passwd *pw;
|
||||
|
||||
pw = getpwuid(getuid());
|
||||
|
||||
l = pw->pw_name;
|
||||
if (pw != NULL)
|
||||
l = pw->pw_name;
|
||||
else
|
||||
l = NULL;
|
||||
#endif
|
||||
|
||||
if ((l == NULL) || (*l == '\0'))
|
||||
|
|
@ -295,8 +298,10 @@ md_gethomedir()
|
|||
char slash = '/';
|
||||
struct passwd *pw;
|
||||
pw = getpwuid(getuid());
|
||||
|
||||
h = pw->pw_dir;
|
||||
if (pw != NULL)
|
||||
h = pw->pw_dir;
|
||||
else
|
||||
h = "";
|
||||
|
||||
if (strcmp(h,"/") == 0)
|
||||
h = NULL;
|
||||
|
|
@ -343,7 +348,10 @@ md_getshell()
|
|||
char *def = "/bin/sh";
|
||||
struct passwd *pw;
|
||||
pw = getpwuid(getuid());
|
||||
s = pw->pw_shell;
|
||||
if (pw != NULL)
|
||||
s = pw->pw_shell;
|
||||
else
|
||||
s = NULL;
|
||||
#endif
|
||||
if ((s == NULL) || (*s == '\0'))
|
||||
if ( (s = getenv("COMSPEC")) == NULL)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue