[v2] always reset DST rules during tzset

Submitted by Benjamin Peterson on Sept. 15, 2018, 5:05 p.m.

Details

Message ID 20180915170524.18964-2-benjamin@python.org
State New
Series "always reset DST rules during tzset"
Headers show

Commit Message

Benjamin Peterson Sept. 15, 2018, 5:05 p.m.
do_tzset() did't always reset the DST transition rules r0 and r1. That means the
rules from older TZ settings could leak into newer ones.

The following program demonstrates this bug. It should print out the same
timezone twice but doesn't due to the leaky state.

int main() {
	time_t t = 0;
	struct tm p;
	setenv("TZ", "STD-1DST", 1);
	localtime_r(&t, &p);
	printf("%s\n", p.tm_zone);
	setenv("TZ", "STD-1DST,M3.2.0,M11.1.0", 1);
	tzset();
	setenv("TZ", "STD-1DST", 1);
	localtime_r(&t, &p);
	printf("%s\n", p.tm_zone);
	return 0;
}
---
 src/time/__tz.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

Patch hide | download patch | download mbox

diff --git a/src/time/__tz.c b/src/time/__tz.c
index 51e66514..185642e8 100644
--- a/src/time/__tz.c
+++ b/src/time/__tz.c
@@ -130,6 +130,8 @@  static void do_tzset()
 
 	if (old_tz && !strcmp(s, old_tz)) return;
 
+	for (i=0; i<5; i++) r0[i] = r1[i] = 0;
+
 	if (zi) __munmap((void *)zi, map_size);
 
 	/* Cache the old value of TZ to check if it has changed. Avoid
@@ -194,7 +196,6 @@  static void do_tzset()
 			const unsigned char *p;
 			__tzname[0] = __tzname[1] = 0;
 			__daylight = __timezone = dst_off = 0;
-			for (i=0; i<5; i++) r0[i] = r1[i] = 0;
 			for (p=types; p<abbrevs; p+=6) {
 				if (!p[4] && !__tzname[0]) {
 					__tzname[0] = (char *)abbrevs + p[5];