[tz] [PATCH 3/4] Fix crash with TZ="EST5EDT4,0/0,J365/25"

Paul Eggert eggert at cs.ucla.edu
Thu Feb 18 03:29:43 UTC 2021


* localtime.c (tzparse): Fix off-by-(stdoffset-dstoffset) bug.
Without this fix, "zdump -v 'EST5EDT4,0/0,J365/25'" would dump
core on some platforms.  This string is an extension to POSIX,
specified by Internet RFC 8536.  No existing tzdb zones use
all-year DST, so this bug should trigger only when TZ is
explicitly set to an all-year DST string.
---
 NEWS        | 4 ++++
 localtime.c | 4 +---
 2 files changed, 5 insertions(+), 3 deletions(-)

diff --git a/NEWS b/NEWS
index a22e8ff..8e968eb 100644
--- a/NEWS
+++ b/NEWS
@@ -8,6 +8,10 @@ Unreleased, experimental changes
 
   Changes to code
 
+    Fix bug that caused 'localtime' etc. to crash when TZ was
+    set to a all-year DST string like "EST5EDT4,0/0,J365/25" that does
+    not conform to POSIX but does conform to Internet RFC 8536.
+
     Fix bug in zic -r; in some cases, the dummy time type after the
     last time transition disagreed with the TZ string, contrary to
     Internet RFC 8563 section 3.3.
diff --git a/localtime.c b/localtime.c
index 82a3b70..333c6ea 100644
--- a/localtime.c
+++ b/localtime.c
@@ -1181,9 +1181,7 @@ tzparse(const char *name, struct state *sp, bool lastditch)
 				}
 				if (reversed
 				    || (starttime < endtime
-					&& (endtime - starttime
-					    < (yearsecs
-					       + (stdoffset - dstoffset))))) {
+					&& endtime - starttime < yearsecs)) {
 					if (TZ_MAX_TIMES - 2 < timecnt)
 						break;
 					sp->ats[timecnt] = janfirst;
-- 
2.27.0



More information about the tz mailing list