From ea4244de9147ad625b73addd984a83df18bcf63b Mon Sep 17 00:00:00 2001 From: "John \"Elwin\" Edwards" Date: Mon, 18 May 2015 10:53:22 -0400 Subject: [PATCH] arogue7, xrogue: prevent potential NULL dereferencing. It is possible for getpwuid() to fail and return NULL. Various md_get* functions now check for this. --- arogue7/mdport.c | 16 ++++++++++------ xrogue/state.c | 16 ++++++++++------ 2 files changed, 20 insertions(+), 12 deletions(-) diff --git a/arogue7/mdport.c b/arogue7/mdport.c index 1768b78..6719a04 100644 --- a/arogue7/mdport.c +++ b/arogue7/mdport.c @@ -235,7 +235,8 @@ md_getusername() pw = getpwuid(getuid()); - l = pw->pw_name; + if (pw != NULL) + l = pw->pw_name; #endif if ((l == NULL) || (*l == '\0')) @@ -266,10 +267,12 @@ md_gethomedir() 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 @@ md_getshell() 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 --git a/xrogue/state.c b/xrogue/state.c index adb0930..3bb7f8c 100644 --- a/xrogue/state.c +++ b/xrogue/state.c @@ -2994,7 +2994,8 @@ md_getusername() pw = getpwuid(getuid()); - l = pw->pw_name; + if (pw != NULL) + l = pw->pw_name; #endif if ((l == NULL) || (*l == '\0')) @@ -3025,10 +3026,12 @@ md_gethomedir() 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 @@ md_getshell() 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)