Skip site navigation (1)Skip section navigation (2)
Date:      Sat, 3 Apr 2010 06:03:55 GMT
From:      NARUSE@FreeBSD.org, Yui <naruse@airemix.jp>
To:        freebsd-gnats-submit@FreeBSD.org
Subject:   misc/145341: localtime doesn't handle overflow
Message-ID:  <201004030603.o3363tYR040535@www.freebsd.org>
Resent-Message-ID: <201004030747.o337l9l0097893@freefall.freebsd.org>

next in thread | raw e-mail | index | archive | help

>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@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:



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201004030603.o3363tYR040535>