Mercurial > hg > early-roguelike
changeset 270:7a96fede6cc8
UltraRogue: check the return value from getpwuid().
It is possible for getpwuid() to return NULL. Such a failure will no
longer cause a segfault. However, the call to getpwuid() may normally
not be reachable.
author | John "Elwin" Edwards |
---|---|
date | Wed, 01 Mar 2017 20:40:18 -0500 |
parents | a413bc97d3ea |
children | 88bd51f231e7 |
files | urogue/mdport.c |
diffstat | 1 files changed, 9 insertions(+), 6 deletions(-) [+] |
line wrap: on
line diff
--- a/urogue/mdport.c Tue Feb 28 21:14:53 2017 -0500 +++ b/urogue/mdport.c Wed Mar 01 20:40:18 2017 -0500 @@ -244,7 +244,8 @@ pw = getpwuid(getuid()); - l = pw->pw_name; + if (pw != NULL) + l = pw->pw_name; #endif if ((l == NULL) || (*l == '\0')) @@ -275,7 +276,8 @@ struct passwd *pw; pw = getpwuid(getuid()); - h = pw->pw_dir; + if (pw != NULL) + h = pw->pw_dir; if (strcmp(h,"/") == 0) h = NULL; @@ -335,7 +337,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) @@ -455,13 +458,13 @@ #if !defined(_WIN32) && !defined(DJGPP) struct passwd *pp; - if ((pp = getpwuid(uid)) == NULL) + if ((pp = getpwuid(uid)) == NULL) { sprintf(uidstr,"%d", uid); return(uidstr); } - else - return(pp->pw_name); + else + return(pp->pw_name); #else sprintf(uidstr,"%d", uid); return(uidstr);