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

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