glibc/time
Joseph Myers 7d7724e795 Fix year 2039 bug for localtime with 64-bit time_t (bug 22639).
Bug 22639 reports localtime failing to handle time offset transitions
correctly in 2039 and later on platforms with 64-bit time_t.

The problem is the use of SECSPERDAY (constant 86400) in calculations
such as

    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;

where t is of type time_t and year is of type int.  Before my commit
92bd70fb85 (an update from tzcode,
included in 2.26 and later releases), SECSPERDAY was obtained from a
file imported from tzcode, where the value included a cast to
int_fast32_t.  On 64-bit platforms, glibc defines int_fast32_t to be
long int, so 64-bit, but my patch resulted in it changing to int.
(The bug would probably have existed even before my patch for x32,
which has 64-bit time_t but 32-bit int_fast32_t, but I haven't
verified that.)

This patch fixes the problem by including a cast to time_t in the
definition of SECSPERDAY.  (64-bit time support for 32-bit systems
should move such code that isn't a public interface to using the
internal 64-bit version of time_t throughout.)

Tested for x86_64 and x86.

	[BZ #22639]
	* time/tzset.c (SECSPERDAY): Cast to time_t.
	* time/tst-y2039.c: New file.
	* time/Makefile (tests): Add tst-y2039.
2021-08-27 17:26:03 -07:00
..
bits/types
sys
adjtime.c
alt_digit.c
asctime.c
bug-asctime_r.c
bug-asctime.c
bug-getdate1.c
bug-mktime1.c
clock.c
clocktest.c
ctime_r.c
ctime.c
datemsk
Depend
difftime.c
dysize.c
era.c
ftime.c
getdate.c
getitimer.c
gettimeofday.c
gmtime.c
lc-time-cleanup.c
localtime.c
Makefile Fix year 2039 bug for localtime with 64-bit time_t (bug 22639). 2021-08-27 17:26:03 -07:00
mktime.c
offtime.c
setitimer.c
settimeofday.c
stime.c
strftime_l.c Abbreviated alternative month names (%Ob) also added (bug 10871). 2018-01-22 11:26:55 +01:00
strftime.c
strptime_l.c Abbreviated alternative month names (%Ob) also added (bug 10871). 2018-01-22 11:26:55 +01:00
strptime.c
test_time.c
time.c
time.h time: Reference CLOCKS_PER_SEC in clock comment [BZ #22735] 2018-02-02 11:59:31 +01:00
timegm.c
timespec_get.c
tst_wcsftime.c
tst-ftime_l.c
tst-ftime.c
tst-getdate.c
tst-mktime2.c
tst-mktime3.c
tst-mktime.c
tst-posixtz.c
tst-strftime.c
tst-strptime2.c
tst-strptime3.c
tst-strptime-whitespace.c
tst-strptime.c ru_RU, ru_UA: Add alternative month names (bug 10871). 2018-01-29 13:14:45 +01:00
tst-tzname.c
tst-y2039.c Fix year 2039 bug for localtime with 64-bit time_t (bug 22639). 2021-08-27 17:26:03 -07:00
tzfile.c
tzset.c Fix year 2039 bug for localtime with 64-bit time_t (bug 22639). 2021-08-27 17:26:03 -07:00
Versions
wcsftime_l.c
wcsftime.c