From 471ef62e97bc4862c9cbbf44d63243e2e9165975 Mon Sep 17 00:00:00 2001 From: Jan Engelhardt Date: Fri, 29 Dec 2023 07:48:41 +0100 Subject: [PATCH 1/2] email_lib: replace make_gmtime/mktime calls by timegm MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit mktime_z(tzalloc("UTC"), x) is the same as timegm(x) — not mktime(x). Fixes: gromox-2.20-64-g5be03997c --- exch/http/mod_cache.cpp | 2 +- lib/email/ical.cpp | 6 +++--- lib/mail_func.cpp | 2 +- mra/imap/imap_cmd_parser.cpp | 2 +- 4 files changed, 6 insertions(+), 6 deletions(-) diff --git a/exch/http/mod_cache.cpp b/exch/http/mod_cache.cpp index 692b83da5..4f262c0a4 100644 --- a/exch/http/mod_cache.cpp +++ b/exch/http/mod_cache.cpp @@ -252,7 +252,7 @@ static BOOL mod_cache_parse_rfc1123_dstring( tmp_tm = {}; if (strptime(dstring, "%a, %d %b %Y %T GMT", &tmp_tm) == nullptr) return FALSE; - *pmtime = mktime(&tmp_tm); + *pmtime = timegm(&tmp_tm); return TRUE; } diff --git a/lib/email/ical.cpp b/lib/email/ical.cpp index c11b8dcdd..c10f71556 100644 --- a/lib/email/ical.cpp +++ b/lib/email/ical.cpp @@ -1316,12 +1316,12 @@ bool ical_itime_to_utc(const ical_component *ptz_component, tmp_tm.tm_wday = 0; tmp_tm.tm_yday = 0; tmp_tm.tm_isdst = 0; - *ptime = mktime(&tmp_tm); + *ptime = timegm(&tmp_tm); if (ptz_component == nullptr) return true; /* * @itime is anchored to @ptz_component. Conversion to tmp_tm did not - * change that. Because mktime() pretends @tmp_tm was UTC, @*ptime + * change that. Because timegm() assumes @tmp_tm was UTC, @*ptime * now has bias which needs to be corrected. */ //assert(itime.type != ICT_UTC); @@ -1353,7 +1353,7 @@ bool ical_datetime_to_utc(const ical_component *ptz_component, tmp_tm.tm_wday = 0; tmp_tm.tm_yday = 0; tmp_tm.tm_isdst = 0; - *ptime = mktime(&tmp_tm); + *ptime = timegm(&tmp_tm); return true; } diff --git a/lib/mail_func.cpp b/lib/mail_func.cpp index ddebf56f1..9643fd18e 100644 --- a/lib/mail_func.cpp +++ b/lib/mail_func.cpp @@ -1015,7 +1015,7 @@ BOOL parse_rfc822_timestamp(const char *str_time, time_t *ptime) return FALSE; } - tmp_time = mktime(&tmp_tm); + tmp_time = timegm(&tmp_tm); tmp_time += factor*(60*60*hour + 60*minute); *ptime = tmp_time; return TRUE; diff --git a/mra/imap/imap_cmd_parser.cpp b/mra/imap/imap_cmd_parser.cpp index ebf516776..8b72c4780 100644 --- a/mra/imap/imap_cmd_parser.cpp +++ b/mra/imap/imap_cmd_parser.cpp @@ -1071,7 +1071,7 @@ static BOOL imap_cmd_parser_convert_imaptime(const char *str_time, time_t *ptime int minute = strtol(tmp_buff, nullptr, 0); if (minute < 0 || minute > 59) return FALSE; - tmp_time = mktime(&tmp_tm); + tmp_time = timegm(&tmp_tm); tmp_time += factor*(60*60*hour + 60*minute); *ptime = tmp_time; return TRUE; From 5278a988b4410362a3d19f1f8a04eb1d286fe014 Mon Sep 17 00:00:00 2001 From: Jan Engelhardt Date: Fri, 29 Dec 2023 07:54:14 +0100 Subject: [PATCH 2/2] oxvcard: replace mktime calls by timegm `mktime(x) - localtime` was the original term which was truncated to `mktime(x)` in a67385c7a. The proper action is to use `timegm`, also because floating allday events are (cf. g_oxcical_allday_ymd) interpreted as UTC midnight out of convenience, and then stored as such (PT_SYSTIME mandates UTC). Fixes: gromox-1.26-67-ga67385c7a --- lib/mapi/oxvcard.cpp | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/lib/mapi/oxvcard.cpp b/lib/mapi/oxvcard.cpp index 070080d32..78c6356af 100644 --- a/lib/mapi/oxvcard.cpp +++ b/lib/mapi/oxvcard.cpp @@ -310,8 +310,7 @@ MESSAGE_CONTENT *oxvcard_import(const VCARD *pvcard, GET_PROPIDS get_propids) tr continue; memset(&tmp_tm, 0, sizeof(tmp_tm)); if (NULL != strptime(pstring, "%Y-%m-%d", &tmp_tm)) { - /* Conversion is not exact */ - tmp_int64 = rop_util_unix_to_nttime(mktime(&tmp_tm)); + tmp_int64 = rop_util_unix_to_nttime(timegm(&tmp_tm)); if (pmsg->proplist.set(PR_BIRTHDAY, &tmp_int64) != 0) return imp_null; } @@ -463,8 +462,7 @@ MESSAGE_CONTENT *oxvcard_import(const VCARD *pvcard, GET_PROPIDS get_propids) tr continue; memset(&tmp_tm, 0, sizeof(tmp_tm)); if (NULL != strptime(pstring, "%Y-%m-%dT%H:%M:%S", &tmp_tm)) { - /* Conversion is not exact */ - tmp_int64 = rop_util_unix_to_nttime(mktime(&tmp_tm)); + tmp_int64 = rop_util_unix_to_nttime(timegm(&tmp_tm)); if (pmsg->proplist.set(PR_LAST_MODIFICATION_TIME, &tmp_int64) != 0) return imp_null; } @@ -585,8 +583,7 @@ MESSAGE_CONTENT *oxvcard_import(const VCARD *pvcard, GET_PROPIDS get_propids) tr continue; memset(&tmp_tm, 0, sizeof(tmp_tm)); if (NULL != strptime(pstring, "%Y-%m-%d", &tmp_tm)) { - /* Conversion is not exact */ - tmp_int64 = rop_util_unix_to_nttime(mktime(&tmp_tm)); + tmp_int64 = rop_util_unix_to_nttime(timegm(&tmp_tm)); if (pmsg->proplist.set(PR_WEDDING_ANNIVERSARY, &tmp_int64) != 0) return imp_null; }