changeset 23:107a467612fb

rogue4: prevent segfault on getpwuid failure
author edwarj4
date Tue, 24 Nov 2009 12:53:15 +0000
parents 63dcd855bc8e
children 4967c46f1320
files rogue4/mach_dep.c rogue4/mdport.c
diffstat 2 files changed, 15 insertions(+), 6 deletions(-) [+]
line wrap: on
line diff
--- 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
--- 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 <stdlib.h>
 #include <string.h>
+#include <errno.h>
 
 #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)