]> git.ipfire.org Git - thirdparty/shadow.git/commitdiff
newgrp: fix segmentation fault 437/head
authorIker Pedrosa <ipedrosa@redhat.com>
Wed, 10 Nov 2021 11:02:04 +0000 (12:02 +0100)
committerIker Pedrosa <ipedrosa@redhat.com>
Wed, 10 Nov 2021 11:02:04 +0000 (12:02 +0100)
Fix segmentation fault in newgrp when xgetspnam() returns a NULL value
that is immediately freed.

The error was committed in
https://github.com/shadow-maint/shadow/commit/e65cc6aebcb4132fa413f00a905216a5b35b3d57

Resolves: https://bugzilla.redhat.com/show_bug.cgi?id=2019553

Signed-off-by: Iker Pedrosa <ipedrosa@redhat.com>
src/newgrp.c

index 730f47e8a1f2c3c56ad76a9d5bfc82ba5c911e1f..566f1c899e2b1cda5751bb6bb8f0e0a43e84f784 100644 (file)
@@ -163,8 +163,8 @@ static void check_perms (const struct group *grp,
        spwd = xgetspnam (pwd->pw_name);
        if (NULL != spwd) {
                pwd->pw_passwd = xstrdup (spwd->sp_pwdp);
+               spw_free (spwd);
        }
-       spw_free (spwd);
 
        if ((pwd->pw_passwd[0] == '\0') && (grp->gr_passwd[0] != '\0')) {
                needspasswd = true;