From 3b01374845f8bbe29ef945b866f679555b28cd38 Mon Sep 17 00:00:00 2001
From: Karel Zak <kzak@redhat.com>
Date: Tue, 30 Apr 2024 10:51:50 +0200
Subject: [PATCH] suL fix use after free on error

Signed-off-by: Karel Zak <kzak@redhat.com>
---
 login-utils/su-common.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/login-utils/su-common.c b/login-utils/su-common.c
index b674920..35950ce 100644
--- a/login-utils/su-common.c
+++ b/login-utils/su-common.c
@@ -446,9 +446,10 @@ static void supam_open_session(struct su_context *su)
 
 	rc = pam_open_session(su->pamh, 0);
 	if (is_pam_failure(rc)) {
+		const char *msg = pam_strerror(su->pamh, rc);
+
 		supam_cleanup(su, rc);
-		errx(EXIT_FAILURE, _("cannot open session: %s"),
-		     pam_strerror(su->pamh, rc));
+		errx(EXIT_FAILURE, _("cannot open session: %s"), msg);
 	} else
 		su->pam_has_session = 1;
 }
-- 
2.43.0

