]> git.ipfire.org Git - thirdparty/openssl.git/commitdiff
Work around a 32-bit mingw failure
authorMatt Caswell <matt@openssl.org>
Thu, 1 Jul 2021 10:58:35 +0000 (11:58 +0100)
committerMatt Caswell <matt@openssl.org>
Fri, 2 Jul 2021 16:44:02 +0000 (17:44 +0100)
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 <tomas@openssl.org>
Reviewed-by: Paul Dale <pauli@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/15939)

test/cmp_hdr_test.c

index 178a1330355f58c5863d3a2503dde16b4f08d849..5a49299b42b113ff58c281b62320fb124d7d544e 100644 (file)
@@ -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);
 }