mailing list of musl libc
 help / color / mirror / code / Atom feed
From: Benjamin Peterson <benjamin@python.org>
To: musl@lists.openwall.com
Subject: [PATCH] always reset DST rules during tzset
Date: Fri, 14 Sep 2018 15:46:55 -0700	[thread overview]
Message-ID: <20180914224655.24718-1-benjamin@python.org> (raw)

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 | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/src/time/__tz.c b/src/time/__tz.c
index 51e66514..3ccfdd5d 100644
--- a/src/time/__tz.c
+++ b/src/time/__tz.c
@@ -130,6 +130,9 @@ static void do_tzset()
 
 	if (old_tz && !strcmp(s, old_tz)) return;
 
+	memset(r0, 0, sizeof r0);
+	memset(r1, 0, sizeof r1);
+
 	if (zi) __munmap((void *)zi, map_size);
 
 	/* Cache the old value of TZ to check if it has changed. Avoid
@@ -194,7 +197,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];
-- 
2.17.1



             reply	other threads:[~2018-09-14 22:46 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-09-14 22:46 Benjamin Peterson [this message]
2018-09-15  1:16 ` Rich Felker
     [not found]   ` <20180915170524.18964-1-benjamin@python.org>
2018-09-15 17:05     ` [PATCH v2] " Benjamin Peterson
2018-09-15 17:20   ` [PATCH] " Benjamin Peterson

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20180914224655.24718-1-benjamin@python.org \
    --to=benjamin@python.org \
    --cc=musl@lists.openwall.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.vuxu.org/mirror/musl/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).