# HG changeset patch # User edwarj4 # Date 1259067195 0 # Node ID 107a467612fbc04d2ce53eb84d2de7bc879979dc # Parent 63dcd855bc8e86f518e0ac07acffa663d4f76ce1 rogue4: prevent segfault on getpwuid failure diff -r 63dcd855bc8e -r 107a467612fb rogue4/mach_dep.c --- a/rogue4/mach_dep.c Mon Nov 16 23:54:24 2009 +0000 +++ b/rogue4/mach_dep.c Tue Nov 24 12:53:15 2009 +0000 @@ -120,7 +120,8 @@ #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 diff -r 63dcd855bc8e -r 107a467612fb rogue4/mdport.c --- a/rogue4/mdport.c Mon Nov 16 23:54:24 2009 +0000 +++ b/rogue4/mdport.c Tue Nov 24 12:53:15 2009 +0000 @@ -53,6 +53,7 @@ #include #include +#include #if defined(_WIN32) && !defined(__MINGW32__) #define PATH_MAX MAX_PATH @@ -265,8 +266,10 @@ 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 @@ 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 @@ 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)