Author: ume
Date: Mon Apr  4 14:57:28 2011
New Revision: 220327
URL: http://svn.freebsd.org/changeset/base/220327

Log:
  MFC r220055: getlogin() may return NULL.

Modified:
  stable/7/usr.bin/su/su.c
Directory Properties:
  stable/7/usr.bin/su/   (props changed)

Modified: stable/7/usr.bin/su/su.c
==============================================================================
--- stable/7/usr.bin/su/su.c    Mon Apr  4 14:54:52 2011        (r220326)
+++ stable/7/usr.bin/su/su.c    Mon Apr  4 14:57:28 2011        (r220327)
@@ -153,7 +153,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;
@@ -258,8 +258,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
_______________________________________________
[email protected] mailing list
http://lists.freebsd.org/mailman/listinfo/svn-src-all
To unsubscribe, send any mail to "[email protected]"

Reply via email to