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>
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);
}
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);
}