]> git.ipfire.org Git - thirdparty/util-linux.git/commitdiff
newgrp: fix memory leak [coverity scan]
authorKarel Zak <kzak@redhat.com>
Fri, 11 Jun 2021 13:10:22 +0000 (15:10 +0200)
committerKarel Zak <kzak@redhat.com>
Fri, 11 Jun 2021 13:10:22 +0000 (15:10 +0200)
Signed-off-by: Karel Zak <kzak@redhat.com>
login-utils/newgrp.c

index 2c0aab114295c206fc2a5c16a1eecd2b53de8a12..2acbc9107e46a1c7c90297ecc833bb9e9f8c7446 100644 (file)
@@ -123,7 +123,7 @@ static int allow_setgid(const struct passwd *pe, const struct group *ge)
 {
        char **look;
        int notfound = 1;
-       char *pwd, *xpwd;
+       char *pwd, *xpwd, *spwd;
 
        if (getuid() == 0)
                /* root may do anything */
@@ -144,8 +144,8 @@ static int allow_setgid(const struct passwd *pe, const struct group *ge)
         * as in /etc/passwd */
 
        /* check /etc/gshadow */
-       if (!(pwd = get_gshadow_pwd(ge->gr_name)))
-               pwd = ge->gr_passwd;
+       spwd = get_gshadow_pwd(ge->gr_name);
+       pwd = spwd ? spwd : ge->gr_passwd;
 
        if (pwd && *pwd && (xpwd = xgetpass(stdin, _("Password: ")))) {
                char *cbuf = crypt(xpwd, pwd);
@@ -162,6 +162,8 @@ static int allow_setgid(const struct passwd *pe, const struct group *ge)
                        return TRUE;
        }
 
+       free(spwd);
+
        /* default to denial */
        return FALSE;
 }