diff mbox

Use 64-bit time_t for time zone file parsing

Message ID 51268a51-c790-43fa-ca0d-d06773a68230@redhat.com
State New, archived
Headers show

Commit Message

Florian Weimer May 18, 2018, 12:11 p.m. UTC
On 05/17/2018 11:06 PM, Joseph Myers wrote:
> Does this use of 64-bit time_t fix bug 19738 ("__tzfile_default 32-bit
> time_t overflow")?  If it does, we should add a testcase for that bug then
> resolve it as FIXED in 2.28.

Looks like it.  Here's a test case which fails before on i386 (assuming 
that the system posixrules file as the required contents) and passes 
afterwards.

I would call the bug fixed because dates where the overflow occurs with 
a 64-bit (internal) time_t are after the expected life-time of the sun, 
where daylight savings time is certainly meaningless.

Thanks,
Florian
diff mbox

Patch

Subject: [PATCH] time: Add test case for bug 19738
To: libc-alpha@sourceware.org

2018-05-18  Florian Weimer  <fweimer@redhat.com>

	[BZ #19738]
	* time/tst-posixrules-overflow.c (do_test): New file.
	* time/Makefile (tests): Add it.

diff --git a/time/Makefile b/time/Makefile
index 0db1206820..5454fe37e3 100644
--- a/time/Makefile
+++ b/time/Makefile
@@ -43,7 +43,7 @@  tests	:= test_time clocktest tst-posixtz tst-strptime tst_wcsftime \
 	   tst-getdate tst-mktime tst-mktime2 tst-ftime_l tst-strftime \
 	   tst-mktime3 tst-strptime2 bug-asctime bug-asctime_r bug-mktime1 \
 	   tst-strptime3 bug-getdate1 tst-strptime-whitespace tst-ftime \
-	   tst-tzname
+	   tst-tzname tst-posixrules-overflow
 
 include ../Rules
 
diff --git a/time/tst-posixrules-overflow.c b/time/tst-posixrules-overflow.c
new file mode 100644
index 0000000000..13d0789a93
--- /dev/null
+++ b/time/tst-posixrules-overflow.c
@@ -0,0 +1,43 @@ 
+/* Check processing of posixrules/TZDEFRULES (bug 19738).
+   Copyright (C) 2018 Free Software Foundation, Inc.
+   This file is part of the GNU C Library.
+
+   The GNU C Library is free software; you can redistribute it and/or
+   modify it under the terms of the GNU Lesser General Public
+   License as published by the Free Software Foundation; either
+   version 2.1 of the License, or (at your option) any later version.
+
+   The GNU C Library is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+   Lesser General Public License for more details.
+
+   You should have received a copy of the GNU Lesser General Public
+   License along with the GNU C Library; if not, see
+   <http://www.gnu.org/licenses/>.  */
+
+#include <stdlib.h>
+#include <support/check.h>
+#include <time.h>
+
+static int
+do_test (void)
+{
+  TEST_COMPARE (setenv ("TZ", "STD+8DST", 1), 0);
+  tzset ();
+  time_t epoch = 1467414184;
+  struct tm *tm = localtime (&epoch);
+  TEST_VERIFY_EXIT (tm != NULL);
+  TEST_COMPARE (tm->tm_year, 2016 - 1900);
+  TEST_COMPARE (tm->tm_mon, 7 - 1);
+  TEST_COMPARE (tm->tm_mday, 1);
+  TEST_COMPARE (tm->tm_hour, 16);
+  TEST_COMPARE (tm->tm_min, 3);
+  TEST_COMPARE (tm->tm_sec, 4);
+  TEST_COMPARE (tm->tm_wday, 5);
+  TEST_COMPARE (tm->tm_yday, 183 - 1);
+  TEST_VERIFY (tm->tm_isdst);
+  return 0;
+}
+
+#include <support/test-driver.c>