From 1949aa0e27d11f678508a0330ccbfc320865f99e Mon Sep 17 00:00:00 2001 From: Richard Russon Date: Mon, 9 Oct 2017 13:39:26 +0100 Subject: [PATCH] fix: prevent timezone overflow 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 | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/lib/date.c b/lib/date.c index 0ac522fbf..675619a50 100644 --- a/lib/date.c +++ b/lib/date.c @@ -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; } /** -- 2.40.0