2de3ab
From 497e90751bc0d95cc998b0f06305040563903948 Mon Sep 17 00:00:00 2001
2de3ab
From: Iker Pedrosa <ipedrosa@redhat.com>
2de3ab
Date: Wed, 10 Nov 2021 12:02:04 +0100
2de3ab
Subject: [PATCH] newgrp: fix segmentation fault
2de3ab
2de3ab
Fix segmentation fault in newgrp when xgetspnam() returns a NULL value
2de3ab
that is immediately freed.
2de3ab
2de3ab
The error was committed in
2de3ab
https://github.com/shadow-maint/shadow/commit/e65cc6aebcb4132fa413f00a905216a5b35b3d57
2de3ab
2de3ab
Resolves: https://bugzilla.redhat.com/show_bug.cgi?id=2019553
2de3ab
2de3ab
Signed-off-by: Iker Pedrosa <ipedrosa@redhat.com>
2de3ab
---
2de3ab
 src/newgrp.c | 2 +-
2de3ab
 1 file changed, 1 insertion(+), 1 deletion(-)
2de3ab
2de3ab
diff --git a/src/newgrp.c b/src/newgrp.c
2de3ab
index 730f47e8..566f1c89 100644
2de3ab
--- a/src/newgrp.c
2de3ab
+++ b/src/newgrp.c
2de3ab
@@ -163,8 +163,8 @@ static void check_perms (const struct group *grp,
2de3ab
 	spwd = xgetspnam (pwd->pw_name);
2de3ab
 	if (NULL != spwd) {
2de3ab
 		pwd->pw_passwd = xstrdup (spwd->sp_pwdp);
2de3ab
+		spw_free (spwd);
2de3ab
 	}
2de3ab
-	spw_free (spwd);
2de3ab
 
2de3ab
 	if ((pwd->pw_passwd[0] == '\0') && (grp->gr_passwd[0] != '\0')) {
2de3ab
 		needspasswd = true;
2de3ab
-- 
2de3ab
2.31.1
2de3ab