changeset 144:708bb2dea17c

arogue7, xrogue: prevent potential NULL dereferencing. It is possible for getpwuid() to fail and return NULL. Various md_get* functions now check for this.
author John "Elwin" Edwards
date Mon, 18 May 2015 10:53:22 -0400
parents 7faf4568c295
children aac28331e71d
files arogue7/mdport.c xrogue/state.c
diffstat 2 files changed, 20 insertions(+), 12 deletions(-) [+]
line wrap: on
line diff
--- a/arogue7/mdport.c	Sat May 16 13:39:26 2015 -0400
+++ b/arogue7/mdport.c	Mon May 18 10:53:22 2015 -0400
@@ -235,7 +235,8 @@
 
     pw = getpwuid(getuid());
 
-    l = pw->pw_name;
+    if (pw != NULL)
+        l = pw->pw_name;
 #endif
 
     if ((l == NULL) || (*l == '\0'))
@@ -266,10 +267,12 @@
     struct passwd *pw;
     pw = getpwuid(getuid());
 
-    h = pw->pw_dir;
-
-    if (strcmp(h,"/") == 0)
-        h = NULL;
+    if (pw != NULL)
+    {
+        h = pw->pw_dir;
+        if (strcmp(h,"/") == 0)
+            h = NULL;
+    }
 #endif
     homedir[0] = 0;
 #ifdef _WIN32
@@ -326,7 +329,8 @@
     char *def = "/bin/sh";
     struct passwd *pw;
     pw = getpwuid(getuid());
-    s = pw->pw_shell;
+    if (pw != NULL)
+        s = pw->pw_shell;
 #endif
     if ((s == NULL) || (*s == '\0'))
         if ( (s = getenv("COMSPEC")) == NULL)
--- a/xrogue/state.c	Sat May 16 13:39:26 2015 -0400
+++ b/xrogue/state.c	Mon May 18 10:53:22 2015 -0400
@@ -2994,7 +2994,8 @@
 
     pw = getpwuid(getuid());
 
-    l = pw->pw_name;
+    if (pw != NULL)
+        l = pw->pw_name;
 #endif
 
     if ((l == NULL) || (*l == '\0'))
@@ -3025,10 +3026,12 @@
     struct passwd *pw;
     pw = getpwuid(getuid());
 
-    h = pw->pw_dir;
-
-    if (strcmp(h,"/") == 0)
-        h = NULL;
+    if (pw != NULL)
+    {
+        h = pw->pw_dir;
+        if (strcmp(h,"/") == 0)
+            h = NULL;
+    }
 #endif
     homedir[0] = 0;
 	
@@ -3124,7 +3127,8 @@
     char *def = "/bin/sh";
     struct passwd *pw;
     pw = getpwuid(getuid());
-    s = pw->pw_shell;
+    if (pw != NULL)
+        s = pw->pw_shell;
 #endif
     if ((s == NULL) || (*s == '\0'))
         if ( (s = getenv("COMSPEC")) == NULL)