From: Matt Caswell Date: Thu, 1 Jul 2021 10:58:35 +0000 (+0100) Subject: Work around a 32-bit mingw failure X-Git-Tag: openssl-3.0.0-beta2~125 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=3c0d0eca3505aabe14024e3dd269dee3692ba1ce;p=thirdparty%2Fopenssl.git Work around a 32-bit mingw failure Passing the return value from gmtime() directly to mktime() was producing incorrect results under windows (but not under wine) when built with mingw 32-bit (but not VC-WIN32). We implement a workaround for this. Reviewed-by: Tomas Mraz Reviewed-by: Paul Dale (Merged from https://github.com/openssl/openssl/pull/15939) --- diff --git a/test/cmp_hdr_test.c b/test/cmp_hdr_test.c index 178a1330355..5a49299b42b 100644 --- a/test/cmp_hdr_test.c +++ b/test/cmp_hdr_test.c @@ -161,21 +161,31 @@ static int test_HDR_set1_recipient(void) static int execute_HDR_update_messageTime_test(CMP_HDR_TEST_FIXTURE *fixture) { - struct tm hdrtm; + struct tm hdrtm, tmptm; time_t hdrtime, before, after, now; now = time(NULL); - before = mktime(gmtime(&now)); + /* + * Trial and error reveals that passing the return value from gmtime + * directly to mktime in a mingw 32 bit build gives unexpected results. To + * work around this we take a copy of the return value first. + */ + tmptm = *gmtime(&now); + before = mktime(&tmptm); + if (!TEST_true(ossl_cmp_hdr_update_messageTime(fixture->hdr))) return 0; if (!TEST_true(ASN1_TIME_to_tm(fixture->hdr->messageTime, &hdrtm))) return 0; hdrtime = mktime(&hdrtm); + if (!TEST_time_t_le(before, hdrtime)) return 0; now = time(NULL); - after = mktime(gmtime(&now)); + tmptm = *gmtime(&now); + after = mktime(&tmptm); + return TEST_time_t_le(hdrtime, after); }