From 2658a4f9b4d7c12ab87c55fc23f298b03ddd5eee Mon Sep 17 00:00:00 2001 From: Logan Chien Date: Wed, 1 Jan 2014 12:27:40 +0800 Subject: [PATCH] Initialize sp->defaulttype in tzparse(). It seems that sp->defaulttype is not initialized by tzparse() at the moment. If we don't initialize sp->defaulttype in tzparse(), we might be able to get incorrect sp->types by default. For example, time_t epoch = 0; setenv("TZ", "UTC+00", 1); tzset(); printf("%s", ctime(&epoch)); // (a) setenv("TZ", "Asia/Taipei", 1); tzset(); printf("%s", ctime(&epoch)); // (b) setenv("TZ", "UTC+00", 1); tzset(); printf("%s", ctime(&epoch)); // (c) In this example, the expected output should be: Thu Jan 1 00:00:00 1970 Thu Jan 1 08:00:00 1970 Thu Jan 1 00:00:00 1970 However, the output is: Thu Jan 1 00:00:00 1970 Thu Jan 1 08:00:00 1970 Thu Jan 1 08:00:00 1970 Because defaulttype is set to 1, and not reset to 0, and old value in types might be used incorrectly. --- localtime.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/localtime.c b/localtime.c index dcfc1cd..5ee2f3b 100644 --- a/localtime.c +++ b/localtime.c @@ -1013,6 +1013,7 @@ tzparse(const char *name, register struct state *const sp, sp->ttis[1].tt_gmtoff = -stdoffset; sp->ttis[1].tt_isdst = 0; sp->ttis[1].tt_abbrind = 0; + sp->defaulttype = 0; timecnt = 0; janfirst = 0; yearlim = EPOCH_YEAR + YEARSPERREPEAT; @@ -1138,6 +1139,7 @@ tzparse(const char *name, register struct state *const sp, sp->ttis[1].tt_isdst = TRUE; sp->ttis[1].tt_abbrind = stdlen + 1; sp->typecnt = 2; + sp->defaulttype = 0; } } else { dstlen = 0; @@ -1147,6 +1149,7 @@ tzparse(const char *name, register struct state *const sp, sp->ttis[0].tt_gmtoff = -stdoffset; sp->ttis[0].tt_isdst = 0; sp->ttis[0].tt_abbrind = 0; + sp->defaulttype = 0; } sp->charcnt = stdlen + 1; if (dstlen != 0) -- 1.7.9.5