summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorIker Pedrosa <ipedrosa@redhat.com>2022-10-06 10:05:44 +0200
committerSerge Hallyn <serge@hallyn.com>2022-10-07 09:53:02 -0500
commitfbf275da195b3f3c762472f6660497f70cb3531e (patch)
treebfec16c7e1530f6fb323785e3b7a348a7aad17ae
parent1e5f9a72b0c49b34d29284528d36bb8bafbd862b (diff)
lastlog: check for localtime() return value
Signed-off-by: Tomáš Mráz <tm@t8m.info> Signed-off-by: Iker Pedrosa <ipedrosa@redhat.com>
-rw-r--r--src/lastlog.c9
1 files 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");
}