lastlog: check for localtime() return value

Signed-off-by: Tomáš Mráz <tm@t8m.info>
Signed-off-by: Iker Pedrosa <ipedrosa@redhat.com>
This commit is contained in:
Iker Pedrosa 2022-10-06 10:05:44 +02:00 committed by Serge Hallyn
parent 1e5f9a72b0
commit fbf275da19

View File

@ -150,9 +150,12 @@ static void print_one (/*@null@*/const struct passwd *pw)
ll_time = ll.ll_time;
tm = localtime (&ll_time);
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");
}