]> git.ipfire.org Git - thirdparty/shadow.git/commitdiff
lastlog: check for localtime() return value
authorIker Pedrosa <ipedrosa@redhat.com>
Thu, 6 Oct 2022 08:05:44 +0000 (10:05 +0200)
committerSerge Hallyn <serge@hallyn.com>
Fri, 7 Oct 2022 14:53:02 +0000 (09:53 -0500)
Signed-off-by: Tomáš Mráz <tm@t8m.info>
Signed-off-by: Iker Pedrosa <ipedrosa@redhat.com>
src/lastlog.c

index 0d4b5fd228d7ffd17858e931f40cdf2447127432..f5c0a5cc8cbb60172ca0bf183f08fd2da6cc080e 100644 (file)
@@ -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");
        }