# HG changeset patch # User John "Elwin" Edwards # Date 1431960802 14400 # Node ID 708bb2dea17c4710a85cb5ece111014efd60b262 # Parent 7faf4568c29544b2a650bc3358b1e1f348fd2733 arogue7, xrogue: prevent potential NULL dereferencing. It is possible for getpwuid() to fail and return NULL. Various md_get* functions now check for this. diff -r 7faf4568c295 -r 708bb2dea17c arogue7/mdport.c --- 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) diff -r 7faf4568c295 -r 708bb2dea17c xrogue/state.c --- 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)