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

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