From 2183d8e5840f69cabf868dc2a232e0dd2bb470a8 Mon Sep 17 00:00:00 2001 From: Steffen Nurpmeso Date: Fri, 16 Feb 2018 21:19:20 +0100 Subject: [PATCH] imap_make_date_time(): more care here, too --- obs-imap.c | 26 ++++++++++++++++++++++---- 1 file changed, 22 insertions(+), 4 deletions(-) diff --git a/obs-imap.c b/obs-imap.c index 0b8fd6a0..979fdb44 100644 --- a/obs-imap.c +++ b/obs-imap.c @@ -4323,6 +4323,7 @@ imap_make_date_time(time_t t) { static char s[40]; char const *mn; + si32_t y, md, th, tm, ts; struct tm *tmp; int tzdiff, tzdiff_hour, tzdiff_min; time_t t2; @@ -4345,12 +4346,29 @@ jredo: if (tmp->tm_isdst > 0) tzdiff_hour++; - mn = (tmp->tm_mon >= 0 && tmp->tm_mon <= 11) - ? n_month_names[tmp->tm_mon] : n_qm; + if(n_UNLIKELY((y = tmp->tm_year) < 0 || y >= 9999/*SI32_MAX*/ - 1900)){ + y = 1970; + mn = n_month_names[0]; + md = 1; + th = tm = ts = 0; + }else{ + y += 1900; + mn = (tmp->tm_mon >= 0 && tmp->tm_mon <= 11) + ? n_month_names[tmp->tm_mon] : n_qm; + + if((md = tmp->tm_mday) < 1 || md > 31) + md = 1; + + if((th = tmp->tm_hour) < 0 || th > 23) + th = 0; + if((tm = tmp->tm_min) < 0 || tm > 59) + tm = 0; + if((ts = tmp->tm_sec) < 0 || ts > 60) + ts = 0; + } snprintf(s, sizeof s, "\"%02d-%s-%04d %02d:%02d:%02d %+03d%02d\"", - tmp->tm_mday, mn, tmp->tm_year + 1900, - tmp->tm_hour, tmp->tm_min, tmp->tm_sec, tzdiff_hour, tzdiff_min); + md, mn, y, th, tm, ts, tzdiff_hour, tzdiff_min); NYD2_LEAVE; return s; } -- 2.11.4.GIT