changeset 6:9a2c0c60c386

Fix segfault on getpwuid failure
author edwarj4
date Fri, 16 Oct 2009 14:30:06 +0000
parents e361fbca47ec
children d388234c4ce9
files rogue3/mdport.c
diffstat 1 files changed, 15 insertions(+), 5 deletions(-) [+]
line wrap: on
line diff
--- a/rogue3/mdport.c	Fri Oct 16 14:21:24 2009 +0000
+++ b/rogue3/mdport.c	Fri Oct 16 14:30:06 2009 +0000
@@ -444,8 +444,11 @@
     struct passwd *pw;
 
     pw = getpwuid(getuid());
-
-    l = pw->pw_name;
+    /* Don't segfault if getpwuid fails (and the thing is wildly possible) */
+    if (pw != NULL)
+	l = pw->pw_name;
+    else
+	l = NULL;
 #endif
 
     if ((l == NULL) || (*l == '\0'))
@@ -475,8 +478,11 @@
     char slash = '/';
     struct passwd *pw;
     pw = getpwuid(getuid());
-
-    h = pw->pw_dir;
+    /* Don't segfault if getpwuid fails */
+    if (pw != NULL)
+	h = pw->pw_dir;
+    else
+	h = NULL;
 
     if (strcmp(h,"/") == 0)
         h = NULL;
@@ -540,7 +546,11 @@
     char *def = "/bin/sh";
     struct passwd *pw;
     pw = getpwuid(getuid());
-    s = pw->pw_shell;
+    /* don't segfault if getpwuid fails */
+    if (pw != NULL)
+	s = pw->pw_shell;
+    else
+	s = NULL;
 #endif
     if ((s == NULL) || (*s == '\0'))
         if ( (s = getenv("COMSPEC")) == NULL)