]> git.ipfire.org Git - thirdparty/util-linux.git/commitdiff
utmpdump: fix localtime() error handling
authorRuediger Meier <ruediger.meier@ga-group.nl>
Wed, 11 Jun 2014 15:31:56 +0000 (17:31 +0200)
committerRuediger Meier <ruediger.meier@ga-group.nl>
Wed, 11 Jun 2014 21:06:32 +0000 (23:06 +0200)
If current TZ has no representation of a given time_t then localtime()
would return NULL and break the next strftime().

In practice this happens very likely on systems with 64bit time_t when
parsing broken binary data. Seen on aarch64 (and probably s390) using
our (incompatible) test wtmp data.

Signed-off-by: Ruediger Meier <ruediger.meier@ga-group.nl>
login-utils/utmpdump.c

index 7611c9f0ac3ca52de8b9fae0ddb2f1ee6b616ed2..e1fefc63e4bfc54eeb54b4182923f9e17b145aae 100644 (file)
 static char *timetostr(const time_t time)
 {
        static char s[29];      /* [Sun Sep 01 00:00:00 1998 PST] */
+       struct tm *tmp;
 
-       if (time != 0)
-               strftime(s, 29, "%a %b %d %T %Y %Z", localtime(&time));
+       if (time != 0 && (tmp = localtime(&time)))
+               strftime(s, 29, "%a %b %d %T %Y %Z", tmp);
        else
                s[0] = '\0';