Blame SOURCES/pam-1.5.1-pam-lastlog-check-localtime_r-return-value.patch

db3d82
From 40c271164dbcebfc5304d0537a42fb42e6b6803c Mon Sep 17 00:00:00 2001
db3d82
From: Iker Pedrosa <ipedrosa@redhat.com>
db3d82
Date: Mon, 26 Sep 2022 12:16:53 +0200
db3d82
Subject: [PATCH] pam_lastlog: check localtime_r() return value
db3d82
db3d82
Check the return value of localtime_r() before calling strftime(). This
db3d82
function crashes if the argument is NULL.
db3d82
db3d82
Resolves: https://bugzilla.redhat.com/show_bug.cgi?id=2012871
db3d82
db3d82
Signed-off-by: Iker Pedrosa <ipedrosa@redhat.com>
db3d82
---
db3d82
 modules/pam_lastlog/pam_lastlog.c | 12 ++++++------
db3d82
 1 file changed, 6 insertions(+), 6 deletions(-)
db3d82
db3d82
diff --git a/modules/pam_lastlog/pam_lastlog.c b/modules/pam_lastlog/pam_lastlog.c
db3d82
index abd048df..121e7560 100644
db3d82
--- a/modules/pam_lastlog/pam_lastlog.c
db3d82
+++ b/modules/pam_lastlog/pam_lastlog.c
db3d82
@@ -573,12 +573,12 @@ last_login_failed(pam_handle_t *pamh, int announce, const char *user, time_t llt
db3d82
 	    time_t lf_time;
db3d82
 
db3d82
 	    lf_time = utuser.ut_tv.tv_sec;
db3d82
-	    tm = localtime_r (&lf_time, &tm_buf);
db3d82
-	    strftime (the_time, sizeof (the_time),
db3d82
-	        /* TRANSLATORS: "strftime options for date of last login" */
db3d82
-		_(" %a %b %e %H:%M:%S %Z %Y"), tm);
db3d82
-
db3d82
-	    date = the_time;
db3d82
+	    if ((tm = localtime_r (&lf_time, &tm_buf)) != NULL) {
db3d82
+	        strftime (the_time, sizeof (the_time),
db3d82
+	            /* TRANSLATORS: "strftime options for date of last login" */
db3d82
+	                  _(" %a %b %e %H:%M:%S %Z %Y"), tm);
db3d82
+	        date = the_time;
db3d82
+	    }
db3d82
 	}
db3d82
 
db3d82
 	/* we want & have the host? */
db3d82
-- 
db3d82
2.38.1
db3d82