NetBSD Problem Report #10521

Received: (qmail 26830 invoked from network); 6 Jul 2000 05:58:54 -0000
Message-Id: <200007060558.e665wsQ07461@capsicum.wsrcc.com>
Date: Wed, 5 Jul 2000 22:58:54 -0700 (PDT)
From: Wolfgang Rupprecht <wolfgang@wsrcc.com>
Reply-To: wolfgang@wsrcc.com
To: gnats-bugs@gnats.netbsd.org
Subject: y2k bug in mktime
X-Send-Pr-Version: 3.95

>Number:         10521
>Category:       lib
>Synopsis:       mktime doesn't like years > 100
>Confidential:   no
>Severity:       serious
>Priority:       medium
>Responsible:    lib-bug-people
>State:          closed
>Class:          sw-bug
>Submitter-Id:   net
>Arrival-Date:   Thu Jul 06 05:59:00 +0000 2000
>Closed-Date:    Thu Jul 06 08:05:10 +0000 2000
>Last-Modified:  Thu Jul 06 16:11:00 +0000 2000
>Originator:     Wolfgang Rupprecht
>Release:        NetBSD-current Jun 9 2000
>Organization:
W S Rupprecht Computer Consulting, Fremont CA
>Environment:

System: NetBSD capsicum.wsrcc.com 1.4ZB NetBSD 1.4ZB (WSRCC) #0: Fri Jun 9 15:31:49 PDT 2000 wolfgang@capsicum.wsrcc.com:/v/src/netbsd/NetBSD-current/usr/src/sys/arch/i386/compile/WSRCC i386


>Description:
	there is a y2k bug in mktime.  It refuses to convert tm
        structs where the year is set to 1996.  The number 96 works 
	just fine.

	marked medium/serious only because of the y2k stigma.

>How-To-Repeat:

(gdb) p tm
$2 = {
  tm_sec = 50, 
  tm_min = 39, 
  tm_hour = 18, 
  tm_mday = 22, 
  tm_mon = 5, 
  tm_year = 1996, 
  tm_wday = 0, 
  tm_yday = 0, 
  tm_isdst = 0, 
  tm_gmtoff = 0, 
  tm_zone = 0x804bc21 "GMT"
}
(gdb) p mktime(&tm)
$3 = -1
(gdb) p tm.tm_year = 96
$4 = 96
(gdb) p tm
$5 = {
  tm_sec = 50, 
  tm_min = 39, 
  tm_hour = 18, 
  tm_mday = 22, 
  tm_mon = 5, 
  tm_year = 96, 
  tm_wday = 0, 
  tm_yday = 0, 
  tm_isdst = 0, 
  tm_gmtoff = 0, 
  tm_zone = 0x804bc21 "GMT"
}
(gdb) p mktime(&tm)
$6 = 835497590

Notice it works for a year of "96" but not a year of "1996".

>Fix:
	damned if I know.  (I can't even remember how many days in any
particualar month.  I'm gonna write code to do it all the way back to
the epoch?)

#ifdef __NetBSD__
		if (tm.tm_year > 100)
		    tm.tm_year %= 100;
#endif

>Release-Note:
>Audit-Trail:

From: Hubert Feyrer <feyrer@rfhs8012.fh-regensburg.de>
To: Wolfgang Rupprecht <wolfgang@wsrcc.com>
Cc: gnats-bugs@gnats.netbsd.org
Subject: Re: lib/10521: y2k bug in mktime
Date: Thu, 6 Jul 2000 09:56:35 +0200 (MET DST)

 On Wed, 5 Jul 2000, Wolfgang Rupprecht wrote:
 > 	there is a y2k bug in mktime.  It refuses to convert tm
 >         structs where the year is set to 1996.  The number 96 works
 > 	just fine.
 ...
 >   tm_year = 1996, 
 ... 
 > Notice it works for a year of "96" but not a year of "1996".

 tm_year is defined as years _since_ 1900, as such you're requesting

 ~3800 here, which is past the unix Y2038 date. No wonder this gives
 fireworks. :-)



  - Hubert

State-Changed-From-To: open->closed 
State-Changed-By: tron 
State-Changed-When: Thu Jul 6 01:02:47 PDT 2000 
State-Changed-Why:  
From "man mktime" on NetBSD, ... 

int tm_year;     /* year - 1900 */ 

Solaris, ... 

int     tm_year;       /* years since 1900 */ 

True Unix ... 

int tm_year      Years since 1900 

and Linux: 

tm_year 
The number of years since 1900. 

Your code is plainly wrong. 

From: Robert Elz <kre@munnari.OZ.AU>
To: wolfgang@wsrcc.com
Cc: gnats-bugs@gnats.netbsd.org
Subject: Re: lib/10521: y2k bug in mktime 
Date: Thu, 06 Jul 2000 18:49:38 +1000

     Date:        Wed, 5 Jul 2000 22:58:54 -0700 (PDT)
     From:        Wolfgang Rupprecht <wolfgang@wsrcc.com>
     Message-ID:  <200007060558.e665wsQ07461@capsicum.wsrcc.com>

   | >Synopsis:       mktime doesn't like years > 100

 Is it that, or just years that are that much bigger that mktime
 has no idea what the rules will be (sticking 1996 in tm_year asks
 mktime to convert the data for the year 3896 AD.)

 The definition of tm_year is "year - 1900".

 kre


From: Jaromír Doleček <dolecek@ibis.cz>
To: wolfgang@wsrcc.com
Cc: gnats-bugs@gnats.netbsd.org
Subject: Re: lib/10521: y2k bug in mktime
Date: Thu, 6 Jul 2000 11:14:50 +0200 (CEST)

 You probably ARE aware that you should pass (year - 1900) in the tm
 passed to mktime(), right ?

 If you pass 1996, it would actually be handled as year 3896
 and won't be handled since time_t is currently 32bit and hence
 can display only years until 204something.

 Jaromir

 Wolfgang Rupprecht wrote:
 > >Description:
 > 	there is a y2k bug in mktime.  It refuses to convert tm
 >         structs where the year is set to 1996.  The number 96 works 
 > 	just fine.
 -- 
 Jaromir Dolecek <jdolecek@NetBSD.org>      http://www.ics.muni.cz/~dolecek/
 @@@@  Wanna a real operating system ? Go and get NetBSD, damn!  @@@@

From: Andrew Brown <atatat@atatdot.net>
To: Wolfgang Rupprecht <wolfgang@wsrcc.com>
Cc: gnats-bugs@gnats.netbsd.org, netbsd-bugs@netbsd.org
Subject: Re: lib/10521: y2k bug in mktime
Date: Thu, 6 Jul 2000 10:03:40 -0400

 >>Description:
 >	there is a y2k bug in mktime.  It refuses to convert tm
 >        structs where the year is set to 1996.  The number 96 works 
 >	just fine.

 that's because the tm_year member of struct tm is defined to be the
 number of years since 1900.  man localtime(3).  the programmer is
 expected to convert dates to this format.

 >#ifdef __NetBSD__
 >		if (tm.tm_year > 100)
 >		    tm.tm_year %= 100;
 >#endif

 not that.  perhap something like

 #ifdef __NetBSD__
 		if (tm.tm_year > 1900)
 		    tm.tm_year %= 1900;
 #endif

 although that's not specifically correct.  someone will soon want to
 be able to represent april 1, 3048ad in a time_t and lose.

 -- 
 |-----< "CODE WARRIOR" >-----|
 codewarrior@daemon.org             * "ah!  i see you have the internet
 twofsonet@graffiti.com (Andrew Brown)                that goes *ping*!"
 andrew@crossbar.com       * "information is power -- share the wealth."

From: Wolfgang Rupprecht <wolfgang@wsrcc.com>
To: Andrew Brown <atatat@atatdot.net>
Cc: gnats-bugs@gnats.netbsd.org, netbsd-bugs@netbsd.org
Subject: Re: lib/10521: y2k bug in mktime
Date: Thu, 6 Jul 2000 08:57:03 -0700 (PDT)

 Andrew Brown writes:
 > that's because the tm_year member of struct tm is defined to be the
 > number of years since 1900.  man localtime(3).  the programmer is
 > expected to convert dates to this format.

 It seems that everyone but me remembered that tm_year is still based
 on a 1900 offset.  I guess we should note this in the
 ctime(3)/mktime(3) man page, which is what I looked at to remind
 myself of the calling convention.

 The fact that most other code has been fixed to deal gracefully with
 4-digit years leads one to *assume* that the rest of the routines will
 follow the principal of least surprise.  Since the computer can DTRT
 in this case I wonder if it wouldn't be better to have mktime()
 understand the normal windowing hack of small-number means offset from
 some epoch (1900, or denis richie's birthday or whatever) and
 large-number means the more conventional year in 4-digit notation.

 The beauty of "standards".  Some of them are down-right
 counter-intuitive.

 -wolfgang
 -- 
 Wolfgang Rupprecht    <wolfgang@wsrcc.com>     http://www.wsrcc.com/wolfgang/
 DGPS signals via the Internet  http://www.wsrcc.com/wolfgang/gps/dgps-ip.html

From: Bill Sommerfeld <sommerfeld@orchard.arlington.ma.us>
To: Wolfgang Rupprecht <wolfgang@wsrcc.com>
Cc: Andrew Brown <atatat@atatdot.net>, gnats-bugs@gnats.netbsd.org,
	netbsd-bugs@netbsd.org
Subject: Re: lib/10521: y2k bug in mktime 
Date: Thu, 06 Jul 2000 12:02:22 -0400

    It seems that everyone but me remembered that tm_year is still based
    on a 1900 offset.  I guess we should note this in the
    ctime(3)/mktime(3) man page, which is what I looked at to remind
    myself of the calling convention.

 It's in there, albeit tersely:

                    int tm_year;     /* year - 1900 */

 Can you suggest some additional text which would have made it obvious?

 					- Bill

From: Hubert Feyrer <feyrer@rfhs8012.fh-regensburg.de>
To: Wolfgang Rupprecht <wolfgang@wsrcc.com>
Cc: Andrew Brown <atatat@atatdot.net>, gnats-bugs@gnats.netbsd.org,
   netbsd-bugs@netbsd.org
Subject: Re: lib/10521: y2k bug in mktime
Date: Thu, 6 Jul 2000 18:09:47 +0200 (MET DST)

 On Thu, 6 Jul 2000, Wolfgang Rupprecht wrote:
 > It seems that everyone but me remembered that tm_year is still based
 > on a 1900 offset.  I guess we should note this in the
 > ctime(3)/mktime(3) man page, which is what I looked at to remind
 > myself of the calling convention.

 Already done:
 cvs rdiff -r1.17 -r1.18 basesrc/lib/libc/time/ctime.3


  - Hubert

 -- 
 NetBSD - because Unix isn't just #include <linux.h>, i386, ILP32, ELF, ...!

>Unformatted:

NetBSD Home
NetBSD PR Database Search

(Contact us) $NetBSD: query-full-pr,v 1.51 2026/08/10 02:28:17 riastradh Exp $
$NetBSD: gnats_config.sh,v 1.10 2026/05/13 22:00:09 riastradh Exp $
Copyright © 1994-2026 The NetBSD Foundation, Inc. ALL RIGHTS RESERVED.