summaryrefslogtreecommitdiffstats
path: root/login-utils/utmpdump.c
diff options
context:
space:
mode:
authorRuediger Meier2014-06-11 17:31:56 +0200
committerRuediger Meier2014-06-11 23:06:32 +0200
commit18df1cc77c20acf0d80cc5c5ef38afa2f3fa148e (patch)
tree0871cba82c2d8ef9278e75a9b6bc06415c7fa87f /login-utils/utmpdump.c
parentlibblkid: cleanup internal return codes (diff)
downloadkernel-qcow2-util-linux-18df1cc77c20acf0d80cc5c5ef38afa2f3fa148e.tar.gz
kernel-qcow2-util-linux-18df1cc77c20acf0d80cc5c5ef38afa2f3fa148e.tar.xz
kernel-qcow2-util-linux-18df1cc77c20acf0d80cc5c5ef38afa2f3fa148e.zip
utmpdump: fix localtime() error handling
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>
Diffstat (limited to 'login-utils/utmpdump.c')
-rw-r--r--login-utils/utmpdump.c5
1 files changed, 3 insertions, 2 deletions
diff --git a/login-utils/utmpdump.c b/login-utils/utmpdump.c
index 7611c9f0a..e1fefc63e 100644
--- a/login-utils/utmpdump.c
+++ b/login-utils/utmpdump.c
@@ -48,9 +48,10 @@
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';