Fix segfault on getpwuid failure
This commit is contained in:
parent
c59dd4061d
commit
2ff3dc0619
1 changed files with 15 additions and 5 deletions
|
|
@ -444,8 +444,11 @@ md_getusername(void)
|
|||
struct passwd *pw;
|
||||
|
||||
pw = getpwuid(getuid());
|
||||
|
||||
l = pw->pw_name;
|
||||
/* Don't segfault if getpwuid fails (and the thing is wildly possible) */
|
||||
if (pw != NULL)
|
||||
l = pw->pw_name;
|
||||
else
|
||||
l = NULL;
|
||||
#endif
|
||||
|
||||
if ((l == NULL) || (*l == '\0'))
|
||||
|
|
@ -475,8 +478,11 @@ md_gethomedir(void)
|
|||
char slash = '/';
|
||||
struct passwd *pw;
|
||||
pw = getpwuid(getuid());
|
||||
|
||||
h = pw->pw_dir;
|
||||
/* Don't segfault if getpwuid fails */
|
||||
if (pw != NULL)
|
||||
h = pw->pw_dir;
|
||||
else
|
||||
h = NULL;
|
||||
|
||||
if (strcmp(h,"/") == 0)
|
||||
h = NULL;
|
||||
|
|
@ -540,7 +546,11 @@ md_getshell(void)
|
|||
char *def = "/bin/sh";
|
||||
struct passwd *pw;
|
||||
pw = getpwuid(getuid());
|
||||
s = pw->pw_shell;
|
||||
/* don't segfault if getpwuid fails */
|
||||
if (pw != NULL)
|
||||
s = pw->pw_shell;
|
||||
else
|
||||
s = NULL;
|
||||
#endif
|
||||
if ((s == NULL) || (*s == '\0'))
|
||||
if ( (s = getenv("COMSPEC")) == NULL)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue