From 985728498a6124dffca2c6356a3e7c8f7511340e Mon Sep 17 00:00:00 2001 From: ume Date: Sun, 27 Mar 2011 12:53:20 +0000 Subject: getpwnam(3) may return NULL. Requested by: nork Reviewed by: Takeharu KATO , nork MFC after: 1 week --- usr.bin/su/su.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) (limited to 'usr.bin') diff --git a/usr.bin/su/su.c b/usr.bin/su/su.c index ce556ce..6557c34 100644 --- a/usr.bin/su/su.c +++ b/usr.bin/su/su.c @@ -149,7 +149,7 @@ int main(int argc, char *argv[]) { static char *cleanenv; - struct passwd *pwd; + struct passwd *pwd = NULL; struct pam_conv conv = { openpam_ttyconv, NULL }; enum tristate iscsh; login_cap_t *lc; @@ -255,8 +255,9 @@ main(int argc, char *argv[]) /* get current login name, real uid and shell */ ruid = getuid(); username = getlogin(); - pwd = getpwnam(username); - if (username == NULL || pwd == NULL || pwd->pw_uid != ruid) + if (username != NULL) + pwd = getpwnam(username); + if (pwd == NULL || pwd->pw_uid != ruid) pwd = getpwuid(ruid); if (pwd == NULL) { #ifdef USE_BSM_AUDIT -- cgit v1.1