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.
This commit is contained in:
John "Elwin" Edwards 2017-03-01 20:40:18 -05:00
parent ee3408932f
commit 9a9c016bae

View file

@ -244,7 +244,8 @@ md_getusername(int uid)
pw = getpwuid(getuid());
l = pw->pw_name;
if (pw != NULL)
l = pw->pw_name;
#endif
if ((l == NULL) || (*l == '\0'))
@ -275,7 +276,8 @@ md_gethomedir()
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 @@ 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)
@ -455,13 +458,13 @@ md_getrealname(int uid)
#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);