From owner-freebsd-bugs@FreeBSD.ORG Sat Apr 3 07:47:09 2010 Return-Path: Delivered-To: freebsd-bugs@hub.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 63CB91065678 for ; Sat, 3 Apr 2010 07:47:09 +0000 (UTC) (envelope-from gnats@FreeBSD.org) Received: from freefall.freebsd.org (freefall.freebsd.org [IPv6:2001:4f8:fff6::28]) by mx1.freebsd.org (Postfix) with ESMTP id 41D2A8FC19 for ; Sat, 3 Apr 2010 07:47:09 +0000 (UTC) Received: from freefall.freebsd.org (localhost [127.0.0.1]) by freefall.freebsd.org (8.14.4/8.14.4) with ESMTP id o337l93l097894 for ; Sat, 3 Apr 2010 07:47:09 GMT (envelope-from gnats@freefall.freebsd.org) Received: (from gnats@localhost) by freefall.freebsd.org (8.14.4/8.14.4/Submit) id o337l9l0097893; Sat, 3 Apr 2010 07:47:09 GMT (envelope-from gnats) Resent-Date: Sat, 3 Apr 2010 07:47:09 GMT Resent-Message-Id: <201004030747.o337l9l0097893@freefall.freebsd.org> Resent-From: FreeBSD-gnats-submit@FreeBSD.org (GNATS Filer) Resent-To: freebsd-bugs@FreeBSD.org Resent-Reply-To: FreeBSD-gnats-submit@FreeBSD.org, NARUSE@FreeBSD.org, Yui Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 941A2106564A for ; Sat, 3 Apr 2010 06:03:55 +0000 (UTC) (envelope-from nobody@FreeBSD.org) Received: from www.freebsd.org (www.freebsd.org [IPv6:2001:4f8:fff6::21]) by mx1.freebsd.org (Postfix) with ESMTP id 832E68FC08 for ; Sat, 3 Apr 2010 06:03:55 +0000 (UTC) Received: from www.freebsd.org (localhost [127.0.0.1]) by www.freebsd.org (8.14.3/8.14.3) with ESMTP id o3363tMg040536 for ; Sat, 3 Apr 2010 06:03:55 GMT (envelope-from nobody@www.freebsd.org) Received: (from nobody@localhost) by www.freebsd.org (8.14.3/8.14.3/Submit) id o3363tYR040535; Sat, 3 Apr 2010 06:03:55 GMT (envelope-from nobody) Message-Id: <201004030603.o3363tYR040535@www.freebsd.org> Date: Sat, 3 Apr 2010 06:03:55 GMT From: NARUSE@FreeBSD.org, Yui To: freebsd-gnats-submit@FreeBSD.org X-Send-Pr-Version: www-3.1 Cc: Subject: misc/145341: localtime doesn't handle overflow X-BeenThere: freebsd-bugs@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Bug reports List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sat, 03 Apr 2010 07:47:09 -0000 >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 #include #include 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: