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>
This commit is contained in:
parent
97772cc329
commit
ee475ab23e
|
@ -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)
|
int strtimeval_iso(struct timeval *tv, int flags, char *buf, size_t bufsz)
|
||||||
{
|
{
|
||||||
struct tm tm;
|
struct tm tm;
|
||||||
|
struct tm *rc;
|
||||||
|
|
||||||
if (flags & ISO_GMTIME)
|
if (flags & ISO_GMTIME)
|
||||||
gmtime_r(&tv->tv_sec, &tm);
|
rc = gmtime_r(&tv->tv_sec, &tm);
|
||||||
else
|
else
|
||||||
localtime_r(&tv->tv_sec, &tm);
|
rc = localtime_r(&tv->tv_sec, &tm);
|
||||||
return format_iso_time(&tm, tv->tv_usec, flags, buf, bufsz);
|
|
||||||
|
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 */
|
/* 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)
|
int strtime_iso(const time_t *t, int flags, char *buf, size_t bufsz)
|
||||||
{
|
{
|
||||||
struct tm tm;
|
struct tm tm;
|
||||||
|
struct tm *rc;
|
||||||
|
|
||||||
if (flags & ISO_GMTIME)
|
if (flags & ISO_GMTIME)
|
||||||
gmtime_r(t, &tm);
|
rc = gmtime_r(t, &tm);
|
||||||
else
|
else
|
||||||
localtime_r(t, &tm);
|
rc = localtime_r(t, &tm);
|
||||||
return format_iso_time(&tm, 0, flags, buf, bufsz);
|
|
||||||
|
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 */
|
/* relative time functions */
|
||||||
|
|
Loading…
Reference in New Issue