diff options
author | J William Piggott | 2017-12-09 20:01:33 +0100 |
---|---|---|
committer | J William Piggott | 2017-12-09 20:01:33 +0100 |
commit | 97772cc329bfa555b38416dc4dcacd4d318560c3 (patch) | |
tree | c6f0c94260bf6d78d3f0233ea7b47f6f9159260e | |
parent | tests: unlocks on failed ts_scsi_debug_init (diff) | |
download | kernel-qcow2-util-linux-97772cc329bfa555b38416dc4dcacd4d318560c3.tar.gz kernel-qcow2-util-linux-97772cc329bfa555b38416dc4dcacd4d318560c3.tar.xz kernel-qcow2-util-linux-97772cc329bfa555b38416dc4dcacd4d318560c3.zip |
lib/timeutils.c: bug fix Segmentation fault
Use reentrant time functions to avoid sending a NULL pointer to
format_iso_time() (and to be reentrant ;). Followup commits test for
errors and tm_year wrapping (illustrated below).
hwclock --utc --noadjfile --predict --date '67768034678849400 seconds'
Segmentation fault
Patched
hwclock --utc --noadjfile --predict --date '67768034678849400 seconds'
-2147481748-01-00 00:10:46.000000-05:00
Signed-off-by: J William Piggott <elseifthen@gmx.com>
-rw-r--r-- | lib/timeutils.c | 8 |
1 files changed, 4 insertions, 4 deletions
diff --git a/lib/timeutils.c b/lib/timeutils.c index fdaa2d4a9..994073700 100644 --- a/lib/timeutils.c +++ b/lib/timeutils.c @@ -462,9 +462,9 @@ int strtimeval_iso(struct timeval *tv, int flags, char *buf, size_t bufsz) struct tm tm; if (flags & ISO_GMTIME) - tm = *gmtime(&tv->tv_sec); + gmtime_r(&tv->tv_sec, &tm); else - tm = *localtime(&tv->tv_sec); + localtime_r(&tv->tv_sec, &tm); return format_iso_time(&tm, tv->tv_usec, flags, buf, bufsz); } @@ -480,9 +480,9 @@ int strtime_iso(const time_t *t, int flags, char *buf, size_t bufsz) struct tm tm; if (flags & ISO_GMTIME) - tm = *gmtime(t); + gmtime_r(t, &tm); else - tm = *localtime(t); + localtime_r(t, &tm); return format_iso_time(&tm, 0, flags, buf, bufsz); } |