Bugtraq mailing list archives

The April Fools 2001 bug in Windows


From: "Richard M. Smith" <rms () PRIVACYFOUNDATION ORG>
Date: Wed, 28 Mar 2001 09:14:06 -0500

Hi,

Attached is a message I wrote 2 years ago about a time-related bug in
Windows.  It turns out the bug is going to hit on this Sunday.
Applications built with certain versions of Visual C++ could
start giving the wrong time of day starting on Sunday.  The problem
will last for a week.

Microsoft released a patch for this problem in early 1999,
and many computers have been updated with a fix.  However,
in some cases applications also need to be updated and it is
very unclear how many of them are deployed with the
bug.  This bug will most likely be present in embedded computers
that are dedicated to doing particular jobs.  These systems
typically don't get software updates as often as desktop
computers.

Some systems that might be affected by the bug include:

   - Airport arrival and departure time monitors
   - Building access control systems
   - Scheduling systems for transportation
   - Hotel wake-up systems

I've attached a second message which details how the problem
also affects programs that use the MFC library.

Here is a Microsoft FAQ about the bug:

   http://msdn.microsoft.com/visualc/headlines/2001.asp

My crystal ball is very fuzzy is if this bug is going
to cause any problems or not.

Richard M. Smith
CTO, Privacy Foundation

========================================================================

From  Thu Jan  7 08:35:45 1999
Date: Thu, 7 Jan 1999 10:18:33 +0100
From: Richard M. Smith
To: NTBUGTRAQ () LISTSERV NTBUGTRAQ COM
Subject: The Windows "April Fools 2001" bug

January 7, 1999

I have discovered a serious bug in Windows which will cause
many Windows applications to give the incorrect time starting
on April 1, 2001.  Although this new bug is not technically a Y2K
bug, it is similar because programs will fail on a particular
day in the next century.

The bug causes Windows applications to give times which are off by one hour
even though the Windows clock shows the correct time.  The bug will continue
for one week until April 8th of 2001, when applications will again show the
correct time.  The bug occurs under Windows 95, 98, and NT.

The problem is caused by the Visual C++ runtime library being
confused and assuming that daylight saving time doesn't start until
April the 8th.  In fact, daylight saving time starts on April 1 in
the year 2001.  The confusion appears to be caused by the fact that
April 1 falls on a Sunday in the year 2001.  The same bug occurs
in other years where April 1 also falls on a Sunday.  The last time this
happened was in 1990 and after 2001 it will occur again in 2007.  If April 1
falls on any other day of the week, the bug does not occur.

I reported the bug to Microsoft on Jan. 5th and got confirmation of
from them on the evening of Jan. 6th.  At the present time, Microsoft told
me that they don't know when a fix will be available for the bug.

For some applications, users should be able to fix the
problem by downloading a new version of the Visual C++ runtime
library DLL, MSVCRT.DLL.  Since the DLL now ships as part of Windows,
I would assume the fixed DLL will be available of the Windows Update
site.

Unfortunately not all applications can be corrected with a new release of
MSVCRT.DLL.  Any applications which statically links with the Visual C++
runtime will have to be fixed by the application vendor.  Users will
have to download the new releases of these kinds of applications.

In my testing, I believe that the bug was introduced in version 4.1 of
Visual C++.  It is present in versions 4.2, 5.0, and 6.0 according to
my testing.

At the present time, the bug has been confirmed only in North American
time zones.  Outside North America it is unknown if the same bug
exists or not.  If it does exists, it may occur on different days
and different years.

I have written a small program in C that tests for the problem.
The source code for the test program is attached to the end of this
message.

This "April Fools 2001" bug is present in the localtime() function, but
is probably also in other functions defined in the C language "time.h"
header file.

Here is the output from the test program under Windows 98:

   0x3AC796D0 = Sunday, April 1, 2001 -- 16:00:00 Eastern Standard Time --
DOY=90
   0x3ACF2B70 = Saturday, April 7, 2001 -- 10:00:00 Eastern Standard Time --
DOY=96
   0x3AD06EE0 = Sunday, April 8, 2001 -- 10:00:00 Eastern Daylight Time --
DOY=97

The hours and time zones are incorrect for April 1st and April 7th.  The
time
on April 8th is correct.

A bit of background.  In the United State and Canada, daylight
saving time (DST) always starts on the first Sunday in April and ends on
the last Sunday in October.  More information of the DST rules can
be found in the article at http://www.energy.ca.gov/daylightsaving.html.

I am interested for folks to test for this same bug in other
operating systems and programming tools.  If you do run any tests,
I would appreciate in hearing the results via Email.  I know that
JavaScript has the bug in Netscape and Internet Explorer as well as
Win32 version of Perl.  Excel and Netscape Java Virtual Machine on
the other hand seem immune to the bug.

Thanks,
Richard M. Smith

----------------------------------------------------------------------------
----

//
// APRIL1.C -- Simple test program for the "April's Fools 2001" bug
//
// by Richard M. Smith
// copyright (C) 1999
//

#include <stdio.h>
#include <time.h>
#include <string.h>

#define SECS_PER_HOUR (60 * 60)
#define SECS_PER_DAY (24 * SECS_PER_HOUR)
#define SECS_PER_YEAR (365 * SECS_PER_DAY)

#define START (3 * SECS_PER_DAY)
#define INCR (23 * SECS_PER_HOUR)
#define MAXTIMES ((0x80000000L - START) / INCR)

void print_time(time_t mytime);

char *month_tab[] =
{
        "January",
        "February",
        "March",
        "April",
        "May",
        "June",
        "July",
        "August",
        "September",
        "October",
        "November",
        "December"
};

char *dow_tab[] =
{
        "Sunday",
        "Monday",
        "Tuesday",
        "Wednesday",
        "Thursday",
        "Friday",
        "Saturday"
};

int main()

{

        print_time(0x3AC796D0);  // Sunday, April 1, 2001
        print_time(0x3ACF2B70);  // Saturday, April 7, 2001
        print_time(0x3AD06EE0);  // Sunday, April 8, 2001
        return 0;

}

//
// print_time -- print out a time_t value converted by localtime()
//

void print_time(time_t mytime)

{

    char month[100];
    char dow[100];
    struct tm *tmp;

    tmp = localtime(&mytime);
    if(tmp == NULL)
    {
        printf("0x%08lX = Invalid time\n", mytime);
        return;
    }
    if(tmp->tm_mon >= 0 && tmp->tm_mon <= 11)
        strcpy(month, month_tab[tmp->tm_mon]);
    else
        sprintf(month, "BadMonth=%d", tmp->tm_mon);
    if(tmp->tm_wday >= 0 && tmp->tm_wday <= 6)
        strcpy(dow, dow_tab[tmp->tm_wday]);
    else
        sprintf(month, "BadDOW=%d", tmp->tm_wday);
    printf("0x%08lX = %s, %s %d, %d -- %d:%02d:%02d %s -- DOY=%d\n",
           mytime, dow, month, tmp->tm_mday, tmp->tm_year + 1900,
           tmp->tm_hour, tmp->tm_min, tmp->tm_sec, _tzname[tmp->tm_isdst !=
0],
           tmp->tm_yday);
    return;

}

=========================================================================

From: "Richard M. Smith"
Subject: MFC and the April Fools 2001 bug
Date: 18 Jan 1999 00:00:00 GMT
Newsgroups: microsoft.public.vc.mfc,microsoft.public.vc.language

Hello,

A couple of weeks ago I reported a serious bug to Microsoft
with the localtime() function of the C runtime library.  This
bug will cause many Windows applications to show the incorrect
time of day starting on April 1, 2001.  The bug will last for one
week.  The bug is due to the Visual C++ runtime library being confused
about the start date for daylight saving time.  Microsoft has
confirmed the bug and is currently working on a fix.

Today I did more research on the bug and found that bug is also
present in the MFC library.  In particular, the two MFC classes
for dealing with times and dates, CTime and COleDateTime,  both
have the bug.  The reason that both classes have the bug because
they call the broken localtime() function as well as mktime()
which I discovered today also has the bug.

I located the April Fools 2001 bug in MFC by first searching
the MFC source code for calls to localtime() and mktime().  I then
confirmed these bugs by building a short C++ test program that uses
CTime and ColeDateTime classes.  This test program displayed the
wrong times when I moved my Windows clock forward to April 1, 2001.

Here are the member functions of MFC which have the "April Fools
2001" bug:

   CTime::CTime
   CTime::GetCurrentTime
   CTime::GetLocalTm
   CTime::GetHour
   CTime::GetDay
   CTime::GetDayOfWeek
   CTime::Format

   COleDateTime::COleDateTime        (with a time_t argument only)
   COleDateTime::GetCurrentTime

The following MFC classes also make use of CTime class so they will
likely hit the "April Fools 2001" bug when dealing with times and dates:

   CTimeSpan
   CFileFind
   CFile
   CGopherFileFind
   COleStreamFile
   CDateTimeCtrl
   CMonthCalCtrl

The C runtime functions with the bug are:

   ctime
   localtime
   mktime
   _strtime
   _strdate

Microsoft has created a Web page for news about the April Fools 2001 bug.
The URL of the page is:

    http://msdn.microsoft.com/visualc/headlines/2001.asp

Richard M. Smith


Current thread: