[Bug time/25653] New: daylight saving time in year 5881581 and later incorrect due to internal function compute_change

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

[Bug time/25653] New: daylight saving time in year 5881581 and later incorrect due to internal function compute_change

glaubitz at physik dot fu-berlin.de
https://sourceware.org/bugzilla/show_bug.cgi?id=25653

            Bug ID: 25653
           Summary: daylight saving time in year 5881581 and later
                    incorrect due to internal function compute_change
           Product: glibc
           Version: unspecified
            Status: UNCONFIRMED
          Severity: minor
          Priority: P2
         Component: time
          Assignee: unassigned at sourceware dot org
          Reporter: dietmar.schindler at manrolandgoss dot com
  Target Milestone: ---

Overview:
The internal function `compute_change(tz_rule *rule, int year)` in
"time/tzset.c" is invoked when daylight saving time is to be set in the
`tm_isdst` member of a `struct tm` e. g. when `localtime` is called. For year
5881581 and later (which could well be handled with a 64-bit `time_t`),
compute_change() yields a wrong result and consequently `tm_isdst` is not set
correctly.

Steps to Reproduce:
# Enter date commands in a shell
> date -d5881580-4-1
> date -d5881581-4-1
# While the first command yields correctly Summer time, the second doesn't

Actual Results:
Tue Apr  1 00:00:00 CEST 5881580
Wed Apr  1 00:00:00 CET 5881581

Expected Results:
Tue Apr  1 00:00:00 CEST 5881580
Wed Apr  1 00:00:00 CEST 5881581

Additional Information:
In `compute_change(tz_rule *rule, int year)` there is:

  /* First set T to January 1st, 0:00:00 GMT in YEAR.  */
  if (year > 1970)
    t = ((year - 1970) * 365
     + /* Compute the number of leapdays between 1970 and YEAR
          (exclusive).  There is a leapday every 4th year ...  */
     + ((year - 1) / 4 - 1970 / 4)
     /* ... except every 100th year ... */
     - ((year - 1) / 100 - 1970 / 100)
     /* ... but still every 400th year.  */
     + ((year - 1) / 400 - 1970 / 400)) * SECSPERDAY;
  else
    t = 0;

Even if `t` (and also SECSPERDAY) has a 64-bit type, the subexpression `((year
- 1970) * 365 …)` is computed as `int` and overflows to a negative value with
`year` 5881581. A possible correction is to change `365` to `365L`.

--
You are receiving this mail because:
You are on the CC list for the bug.
Reply | Threaded
Open this post in threaded view
|

[Bug time/25653] daylight saving time in year 5881581 and later incorrect due to internal function compute_change

glaubitz at physik dot fu-berlin.de
https://sourceware.org/bugzilla/show_bug.cgi?id=25653

Dietmar Schindler <dietmar.schindler at manrolandgoss dot com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |dietmar.schindler@manroland
                   |                            |goss.com

--
You are receiving this mail because:
You are on the CC list for the bug.