]> granicus.if.org Git - neomutt/commitdiff
fix: prevent timezone overflow 830/head
authorRichard Russon <rich@flatcap.org>
Mon, 9 Oct 2017 12:39:26 +0000 (13:39 +0100)
committerRichard Russon <rich@flatcap.org>
Sat, 14 Oct 2017 14:51:27 +0000 (15:51 +0100)
On 32-bit arches it's easy to over-/under-flow the date.
We replace these with the max/min values allowed in a time_t.

When we encounter one of these dates, pretend it's UTC to prevent
another overflow.

Fixes #819
Fixes #820

lib/date.c

index 0ac522fbf8f6831d62e724d6b4b4d9dcdb71309d..675619a5018be0775f6a83983adb16654ccc0850 100644 (file)
@@ -220,6 +220,10 @@ static const char *uncomment_timezone(char *buf, size_t buflen, const char *tz)
  */
 time_t mutt_local_tz(time_t t)
 {
+  /* Check we haven't overflowed the time (on 32-bit arches) */
+  if ((t == TIME_T_MAX) || (t == TIME_T_MIN))
+    return 0;
+
   struct tm *ptm = NULL;
   struct tm utc;
 
@@ -591,7 +595,12 @@ time_t mutt_parse_date(const char *s, struct Tz *tz_out)
     tz_out->zoccident = zoccident;
   }
 
-  return (mutt_mktime(&tm, 0) + tz_offset);
+  time_t time = mutt_mktime(&tm, 0);
+  /* Check we haven't overflowed the time (on 32-bit arches) */
+  if ((time != TIME_T_MAX) && (time != TIME_T_MIN))
+    time += tz_offset;
+
+  return time;
 }
 
 /**