getpwnam(3) may return NULL.

Requested by:   nork
Reviewed by:    Takeharu KATO <takeharu1219__at__ybb.ne.jp>, nork
MFC after:      1 week
This commit is contained in:
Hajimu UMEMOTO 2011-03-27 12:53:20 +00:00
parent 4aa18e9d93
commit 3db78cf013
Notes: svn2git 2020-12-20 02:59:44 +00:00
svn path=/head/; revision=220055

View file

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