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
|
#ifdef SIGBUS
|
||||||
signal(SIGBUS, auto_save);
|
signal(SIGBUS, auto_save);
|
||||||
#endif
|
#endif
|
||||||
signal(SIGSEGV, auto_save);
|
/* Don't bother saving a game that segfaulted. */
|
||||||
|
signal(SIGSEGV, SIG_DFL);
|
||||||
#ifdef SIGSYS
|
#ifdef SIGSYS
|
||||||
signal(SIGSYS, auto_save);
|
signal(SIGSYS, auto_save);
|
||||||
#endif
|
#endif
|
||||||
|
|
|
||||||
|
|
@ -53,6 +53,7 @@ char *strdup(const char *s);
|
||||||
|
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
#include <errno.h>
|
||||||
|
|
||||||
#if defined(_WIN32) && !defined(__MINGW32__)
|
#if defined(_WIN32) && !defined(__MINGW32__)
|
||||||
#define PATH_MAX MAX_PATH
|
#define PATH_MAX MAX_PATH
|
||||||
|
|
@ -265,8 +266,10 @@ md_getusername(int uid)
|
||||||
struct passwd *pw;
|
struct passwd *pw;
|
||||||
|
|
||||||
pw = getpwuid(getuid());
|
pw = getpwuid(getuid());
|
||||||
|
if (pw != NULL)
|
||||||
l = pw->pw_name;
|
l = pw->pw_name;
|
||||||
|
else
|
||||||
|
l = NULL;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
if ((l == NULL) || (*l == '\0'))
|
if ((l == NULL) || (*l == '\0'))
|
||||||
|
|
@ -295,8 +298,10 @@ md_gethomedir()
|
||||||
char slash = '/';
|
char slash = '/';
|
||||||
struct passwd *pw;
|
struct passwd *pw;
|
||||||
pw = getpwuid(getuid());
|
pw = getpwuid(getuid());
|
||||||
|
if (pw != NULL)
|
||||||
h = pw->pw_dir;
|
h = pw->pw_dir;
|
||||||
|
else
|
||||||
|
h = "";
|
||||||
|
|
||||||
if (strcmp(h,"/") == 0)
|
if (strcmp(h,"/") == 0)
|
||||||
h = NULL;
|
h = NULL;
|
||||||
|
|
@ -343,7 +348,10 @@ md_getshell()
|
||||||
char *def = "/bin/sh";
|
char *def = "/bin/sh";
|
||||||
struct passwd *pw;
|
struct passwd *pw;
|
||||||
pw = getpwuid(getuid());
|
pw = getpwuid(getuid());
|
||||||
s = pw->pw_shell;
|
if (pw != NULL)
|
||||||
|
s = pw->pw_shell;
|
||||||
|
else
|
||||||
|
s = NULL;
|
||||||
#endif
|
#endif
|
||||||
if ((s == NULL) || (*s == '\0'))
|
if ((s == NULL) || (*s == '\0'))
|
||||||
if ( (s = getenv("COMSPEC")) == NULL)
|
if ( (s = getenv("COMSPEC")) == NULL)
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue