[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Bug#196177: libc6: mktime mishandles dates before 1970 (regression from 3.0r1)



Package: libc6
Version: 2.3.1-16
Severity: normal
Tags: patch

I ran into this problem because I assigned a Python programming time
zone problem to my students
<http://www.cs.ucla.edu/classes/spring03/cs131/hw/pr2.html>.  Students
who were running Debian testing could not do the assignment because
their programs mishandled dates before 1970.  Students who were
running Debian stable (3.0r1) worked fine, as did students running
Solaris.  So this is a regression from 3.0r1.

The problem is that in libc6 2.3.1-16, mktime always returns -1 for
dates that are before 1970.

Here is a patch:

http://savannah.gnu.org/cgi-bin/viewcvs/gnulib/gnulib/lib/mktime.c.diff?r1=1.35&r2=1.36

Here is a test program illustrating the bug:

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

struct tm tm, tm0;

int
main (void)
{
  time_t t;

  tm0.tm_sec = 0;
  tm0.tm_min = 0;
  tm0.tm_hour = 0;
  tm0.tm_year = 1968 - 1900;
  tm0.tm_mon = 1 - 1;
  tm0.tm_mday = 1;
  tm = tm0;

  putenv ("TZ=UTC0");
  t = mktime (&tm);

  if (t != (time_t) -1
      && tm.tm_sec == tm0.tm_sec
      && tm.tm_min == tm0.tm_min
      && tm.tm_hour == tm0.tm_hour
      && tm.tm_mday == tm0.tm_mday
      && tm.tm_mon == tm0.tm_mon
      && tm.tm_year == tm0.tm_year)
    {
      printf ("test succeeded\n");
      return 0;
    }
  else
    {
      printf ("test failed\n");
      return 1;
    }
}



Reply to: