From fbf275da195b3f3c762472f6660497f70cb3531e Mon Sep 17 00:00:00 2001 From: Iker Pedrosa Date: Thu, 6 Oct 2022 10:05:44 +0200 Subject: [PATCH] lastlog: check for localtime() return value MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Tomáš Mráz Signed-off-by: Iker Pedrosa --- src/lastlog.c | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/src/lastlog.c b/src/lastlog.c index 0d4b5fd2..f5c0a5cc 100644 --- a/src/lastlog.c +++ b/src/lastlog.c @@ -150,9 +150,12 @@ static void print_one (/*@null@*/const struct passwd *pw) ll_time = ll.ll_time; tm = localtime (&ll_time); - strftime (ptime, sizeof (ptime), "%a %b %e %H:%M:%S %z %Y", tm); - cp = ptime; - + if (tm == NULL) { + cp = "(unknown)"; + } else { + strftime (ptime, sizeof (ptime), "%a %b %e %H:%M:%S %z %Y", tm); + cp = ptime; + } if (ll.ll_time == (time_t) 0) { cp = _("**Never logged in**\0"); }