From nobody@FreeBSD.org  Sat Jul  6 16:16:02 2002
Return-Path: <nobody@FreeBSD.org>
Received: from mx1.FreeBSD.org (mx1.FreeBSD.org [216.136.204.125])
	by hub.freebsd.org (Postfix) with ESMTP id 7B52837B400
	for <freebsd-gnats-submit@FreeBSD.org>; Sat,  6 Jul 2002 16:16:02 -0700 (PDT)
Received: from www.freebsd.org (www.FreeBSD.org [216.136.204.117])
	by mx1.FreeBSD.org (Postfix) with ESMTP id 3B2FB43E09
	for <freebsd-gnats-submit@FreeBSD.org>; Sat,  6 Jul 2002 16:16:02 -0700 (PDT)
	(envelope-from nobody@FreeBSD.org)
Received: from www.freebsd.org (localhost [127.0.0.1])
	by www.freebsd.org (8.12.4/8.12.4) with ESMTP id g66NG1OT080601
	for <freebsd-gnats-submit@FreeBSD.org>; Sat, 6 Jul 2002 16:16:01 -0700 (PDT)
	(envelope-from nobody@www.freebsd.org)
Received: (from nobody@localhost)
	by www.freebsd.org (8.12.4/8.12.4/Submit) id g66NG19j080600;
	Sat, 6 Jul 2002 16:16:01 -0700 (PDT)
Message-Id: <200207062316.g66NG19j080600@www.freebsd.org>
Date: Sat, 6 Jul 2002 16:16:01 -0700 (PDT)
From: Martin Mller <martin@bnc.ch>
To: freebsd-gnats-submit@FreeBSD.org
Subject: mktime returns -1 for certain dates/timezones when it should normalize
X-Send-Pr-Version: www-1.0

>Number:         40278
>Category:       bin
>Synopsis:       mktime returns -1 for certain dates/timezones when it should normalize
>Confidential:   no
>Severity:       serious
>Priority:       medium
>Responsible:    gavin
>State:          closed
>Quarter:        
>Keywords:       
>Date-Required:  
>Class:          sw-bug
>Submitter-Id:   current-users
>Arrival-Date:   Sat Jul 06 16:20:01 PDT 2002
>Closed-Date:    Thu May 15 15:08:55 UTC 2008
>Last-Modified:  Thu May 15 15:08:55 UTC 2008
>Originator:     Martin Mller
>Release:        4.6-STABLE
>Organization:
Business Network Communications AG
>Environment:
FreeBSD taos.bnc.ch 4.6-STABLE FreeBSD 4.6-STABLE #0: Sun Jun 16 20:17:27 CEST 2002     root@laguna.bnc.ch:/usr/obj/usr/src/sys/BNC-MP-4.6  i386      
>Description:
When adding one month to Fri Mar  1 02:00:00 2002 and at the same time changing tm_mday to zero (should return last day of March) by calling mktime with a struct tm, the return is -1.

This behaviour seems to occur when using dates that do not really exist because of DST and mktime is not able to recover during normalization.
>How-To-Repeat:
Put your computer in CEST timezone, fill in a struct tm to match
Fri Mar  1 02:00:00 2002, call mktime. Then tm_mon +=1 and tm_mday = 0, call mktime again, this will return -1. If you call mktime two times, changing only one value at a time, the output is correct (because mktime will normalize struct tm correctly).      
>Fix:
Possibly by changing "timesub(&t, ttisp->tt_gmtoff, sp, tmp);"
to "timesub(&t, 0L, sp, tmp);" at ligne 1078 in localtime.c (/usr/src/lib/libc/stdtime/).
>Release-Note:
>Audit-Trail:

From: Marc Olzheim <marcolz@stack.nl>
To: bug-followup@FreeBSD.org, martin@bnc.ch
Cc: freebsd-stable@freebsd.org
Subject: Re: bin/40278: mktime returns -1 for certain dates/timezones when it should normalize
Date: Thu, 15 May 2008 10:51:54 +0200

 With the testcode I put on
 http://www.stack.nl/~marcolz/FreeBSD/pr-bin-40278/40278.c I can
 reproduce it on FreeBSD 4.11:
 
 output on 4.11-STABLE
 ------
 
 Init: mktime: 1014944400 Fri Mar  1 02:00:00 CET 2002
 1: mktime: 4294967295 Fri Apr  0 02:00:00 CET 2002
 
 Init: mktime: 1014944400 Fri Mar  1 02:00:00 CET 2002
 2a: mktime: 1017622800 Mon Apr  1 03:00:00 CEST 2002
 2b: mktime: 1017536400 Sun Mar 31 03:00:00 CEST 2002
 
 Init: mktime: 1014944400 Fri Mar  1 02:00:00 CET 2002
 3a: mktime: 1014858000 Thu Feb 28 02:00:00 CET 2002
 3b: mktime: 1017277200 Thu Mar 28 02:00:00 CET 2002
 ------
 
 But it is fixed on my FreeBSD 6.x and up systems:
 
 output on 6.3-PRERELEASE:
 ------
 
 Init: mktime: 1014944400 Fri Mar  1 02:00:00 CET 2002
 1: mktime: 1017536400 Sun Mar 31 03:00:00 CEST 2002
 
 Init: mktime: 1014944400 Fri Mar  1 02:00:00 CET 2002
 2a: mktime: 1017622800 Mon Apr  1 03:00:00 CEST 2002
 2b: mktime: 1017536400 Sun Mar 31 03:00:00 CEST 2002
 
 Init: mktime: 1014944400 Fri Mar  1 02:00:00 CET 2002
 3a: mktime: 1014858000 Thu Feb 28 02:00:00 CET 2002
 3b: mktime: 1017277200 Thu Mar 28 02:00:00 CET 2002
 ------
 
 So it looks like it has been fixed in the mean time and that this PR can
 be closed.
 
 Marc
State-Changed-From-To: open->feedback 
State-Changed-By: gavin 
State-Changed-When: Thu May 15 14:01:39 UTC 2008 
State-Changed-Why:  
To submitter:  Sorry it's taken so long to get a response to this PR, 
however it looks like this may have been fixed long ago, and it 
doesn't look like the problem can be recreated on 6.3 at least.  Are 
you able to confirm that this bug has indeed been fixed? 


Responsible-Changed-From-To: freebsd-bugs->gavin 
Responsible-Changed-By: gavin 
Responsible-Changed-When: Thu May 15 14:01:39 UTC 2008 
Responsible-Changed-Why:  
Track 

http://www.freebsd.org/cgi/query-pr.cgi?pr=40278 
State-Changed-From-To: feedback->closed 
State-Changed-By: gavin 
State-Changed-When: Thu May 15 15:07:07 UTC 2008 
State-Changed-Why:  
Close, mail to submitter bounces, and we have a user who is able to 
recreate it on 4.x but not on 6.x. (Thanks Marc Olzheim for testing!) 

http://www.freebsd.org/cgi/query-pr.cgi?pr=40278 
>Unformatted:
