740027
From a10acfb1d2118f9a180181d3fed5399dbbe1df3c Mon Sep 17 00:00:00 2001
740027
From: Pádraig Brady <P@draigBrady.com>
740027
Date: Tue, 25 Feb 2014 10:58:48 +0000
740027
Subject: parse-datetime: fix crash or infloop in TZ="" parsing
740027
740027
This was reported in http://bugs.gnu.org/16872
740027
from the coreutils command: date -d 'TZ="""'
740027
740027
The infinite loop for this case was present since the
740027
initial TZ="" parsing support in commit de95bdc2 29-10-2004.
740027
This was changed to a crash or heap corruption depending
740027
on the platform with commit 2e3e4195 18-01-2010.
740027
740027
* lib/parse-datetime.y (parse_datetime): Break out of the
740027
TZ="" parsing loop once the second significant " is found.
740027
Also skip over any subsequent whitespace to be consistent
740027
with the non TZ= case.
740027
---
740027
diff --git a/lib/parse-datetime.y b/lib/parse-datetime.y
740027
index 6ece765..0ba0a52 100644
740027
--- a/lib/parse-datetime.y
740027
+++ b/lib/parse-datetime.y
740027
@@ -1303,8 +1303,6 @@ parse_datetime (struct timespec *result, char const *p,
740027
             char tz1buf[TZBUFSIZE];
740027
             bool large_tz = TZBUFSIZE < tzsize;
740027
             bool setenv_ok;
740027
-            /* Free tz0, in case this is the 2nd or subsequent time through. */
740027
-            free (tz0);
740027
             tz0 = get_tz (tz0buf);
740027
             z = tz1 = large_tz ? xmalloc (tzsize) : tz1buf;
740027
             for (s = tzbase; *s != '"'; s++)
740027
@@ -1316,7 +1314,12 @@ parse_datetime (struct timespec *result, char const *p,
740027
             if (!setenv_ok)
740027
               goto fail;
740027
             tz_was_altered = true;
740027
+
740027
             p = s + 1;
740027
+            while (c = *p, c_isspace (c))
740027
+              p++;
740027
+
740027
+            break;
740027
           }
740027
     }
740027
 
740027
--
740027
cgit v0.9.0.2