summaryrefslogtreecommitdiffstats
path: root/lib/timeutils.c
diff options
context:
space:
mode:
authorJ William Piggott2017-12-09 20:40:05 +0100
committerJ William Piggott2017-12-09 20:40:05 +0100
commitee475ab23e17ed85d942229773f72147228fc812 (patch)
tree326a0fb8bcd17402572e3db90ef0e9a5e61592cb /lib/timeutils.c
parentlib/timeutils.c: bug fix Segmentation fault (diff)
downloadkernel-qcow2-util-linux-ee475ab23e17ed85d942229773f72147228fc812.tar.gz
kernel-qcow2-util-linux-ee475ab23e17ed85d942229773f72147228fc812.tar.xz
kernel-qcow2-util-linux-ee475ab23e17ed85d942229773f72147228fc812.zip
lib/timeutils.c:strxxx_iso: test conversion errors
Test for libc time conversion errors in ISO time format functions. hwclock --utc --noadjfile --predict --date '67768034678846520 seconds' Segmentation fault Patched: hwclock --utc --noadjfile --predict --date '67768034678846520 seconds' hwclock: time 67768036191695381 is out of range. Comparable to date(1): date --date '67768034678846520 seconds' date: time 67768036191695384 is out of range Signed-off-by: J William Piggott <elseifthen@gmx.com>
Diffstat (limited to 'lib/timeutils.c')
-rw-r--r--lib/timeutils.c24
1 files changed, 18 insertions, 6 deletions
diff --git a/lib/timeutils.c b/lib/timeutils.c
index 994073700..dd763ecc3 100644
--- a/lib/timeutils.c
+++ b/lib/timeutils.c
@@ -460,12 +460,18 @@ static int format_iso_time(struct tm *tm, suseconds_t usec, int flags, char *buf
int strtimeval_iso(struct timeval *tv, int flags, char *buf, size_t bufsz)
{
struct tm tm;
+ struct tm *rc;
if (flags & ISO_GMTIME)
- gmtime_r(&tv->tv_sec, &tm);
+ rc = gmtime_r(&tv->tv_sec, &tm);
else
- localtime_r(&tv->tv_sec, &tm);
- return format_iso_time(&tm, tv->tv_usec, flags, buf, bufsz);
+ rc = localtime_r(&tv->tv_sec, &tm);
+
+ if (rc)
+ return format_iso_time(&tm, tv->tv_usec, flags, buf, bufsz);
+
+ warnx(_("time %ld is out of range."), tv->tv_sec);
+ return -1;
}
/* struct tm to ISO 8601 */
@@ -478,12 +484,18 @@ int strtm_iso(struct tm *tm, int flags, char *buf, size_t bufsz)
int strtime_iso(const time_t *t, int flags, char *buf, size_t bufsz)
{
struct tm tm;
+ struct tm *rc;
if (flags & ISO_GMTIME)
- gmtime_r(t, &tm);
+ rc = gmtime_r(t, &tm);
else
- localtime_r(t, &tm);
- return format_iso_time(&tm, 0, flags, buf, bufsz);
+ rc = localtime_r(t, &tm);
+
+ if (rc)
+ return format_iso_time(&tm, 0, flags, buf, bufsz);
+
+ warnx(_("time %ld is out of range."), (long)t);
+ return -1;
}
/* relative time functions */