diff arogue7/mdport.c @ 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 b786053d2f37
children aac28331e71d
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)