arogue7, xrogue: prevent potential NULL dereferencing.

It is possible for getpwuid() to fail and return NULL.  Various md_get*
functions now check for this.
This commit is contained in:
John "Elwin" Edwards 2015-05-18 10:53:22 -04:00
parent 3554339257
commit ea4244de91
2 changed files with 20 additions and 12 deletions

View file

@ -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)

View file

@ -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)