Mercurial > hg > early-roguelike
diff xrogue/state.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 | 7faf4568c295 |
children | 1af259ac4ed2 |
line wrap: on
line diff
--- 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)