misc/145341: localtime doesn't handle overflow
NARUSE at FreeBSD.org
NARUSE at FreeBSD.org
Sat Apr 3 07:47:09 UTC 2010
>Number: 145341
>Category: misc
>Synopsis: localtime doesn't handle overflow
>Confidential: no
>Severity: non-critical
>Priority: low
>Responsible: freebsd-bugs
>State: open
>Quarter:
>Keywords:
>Date-Required:
>Class: sw-bug
>Submitter-Id: current-users
>Arrival-Date: Sat Apr 03 07:47:08 UTC 2010
>Closed-Date:
>Last-Modified:
>Originator: NARUSE, Yui
>Release: FreeBSD 8.0-STABLE amd64
>Organization:
>Environment:
FreeBSD windy.airemix.net 8.0-STABLE FreeBSD 8.0-STABLE #9: Fri Feb 26 20:47:20 JST 2010 root at windy.airemix.net:/usr/obj/usr/src/sys/GENERIC amd64
>Description:
gmtime, gmtime_r, localtime and localtime_r may overflow
when the value of year is beyond signed int: year 2147481747 problem.
POSIX says, on such overflow gmtime() shall return NULL
and set errnor as EOVERFLOW, but FreeBSD 8 doesn't.
http://www.opengroup.org/onlinepubs/9699919799/functions/gmtime.html
>How-To-Repeat:
Run following code:
----------
#include <stdio.h>
#include <time.h>
#include <errno.h>
void t_inspect(time_t t)
{
struct tm *tp;
errno = 0;
tp = gmtime(&t);
printf("t:%ld, tp: %p errno:%d\n",t,tp,errno);
if (tp)
printf("sec: %d, min:%d, hour:%d, mday:%d, mon:%d, year:%d,\n" \
"wday:%d, yday:%d, isdst:%d, gmtoff: %ld, zone: %s\n",
tp->tm_sec, tp->tm_min, tp->tm_hour, tp->tm_mday,
tp->tm_mon, tp->tm_year, tp->tm_wday, tp->tm_yday,
tp->tm_isdst, tp->tm_gmtoff, tp->tm_zone);
}
int main(void)
{
time_t t = 67767976233532799;
t_inspect(t-1);
t_inspect(t);
t_inspect(t+1);
return 0;
}
----------
and got following result; second and third output equal.
----------
t:67767976233532798, tp: 0x80099c900 errno:2
sec: 58, min:59, hour:23, mday:31, mon:11, year:2147481747,
wday:2, yday:364, isdst:0, gmtoff: 0, zone: UTC
t:67767976233532799, tp: 0x80099c900 errno:0
sec: 59, min:59, hour:23, mday:31, mon:11, year:2147481747,
wday:2, yday:364, isdst:0, gmtoff: 0, zone: UTC
t:67767976233532800, tp: 0x80099c900 errno:0
sec: 59, min:59, hour:23, mday:31, mon:11, year:2147481747,
wday:2, yday:364, isdst:0, gmtoff: 0, zone: UTC
>Fix:
>Release-Note:
>Audit-Trail:
>Unformatted:
More information about the freebsd-bugs
mailing list