summaryrefslogtreecommitdiffstats
path: root/usr.bin
diff options
context:
space:
mode:
authorume <ume@FreeBSD.org>2011-03-27 12:53:20 +0000
committerume <ume@FreeBSD.org>2011-03-27 12:53:20 +0000
commit985728498a6124dffca2c6356a3e7c8f7511340e (patch)
tree90c0218a926af96d4e0cbaac036466bc8cb697a8 /usr.bin
parent8e19e21cb30b56a8b256510d47566bdcd22015e9 (diff)
downloadFreeBSD-src-985728498a6124dffca2c6356a3e7c8f7511340e.zip
FreeBSD-src-985728498a6124dffca2c6356a3e7c8f7511340e.tar.gz
getpwnam(3) may return NULL.
Requested by: nork Reviewed by: Takeharu KATO <takeharu1219__at__ybb.ne.jp>, nork MFC after: 1 week
Diffstat (limited to 'usr.bin')
-rw-r--r--usr.bin/su/su.c7
1 files changed, 4 insertions, 3 deletions
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
OpenPOWER on IntegriCloud