From 3e6222dacb0d98acd7cb9d0f4b3277056c6627f3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Manuel=20P=C3=A9gouri=C3=A9-Gonnard?= Date: Mon, 29 Jan 2018 10:16:30 +0100 Subject: [PATCH] Fix alarm(0) failure on mingw32 A new test for mbedtls_timing_alarm(0) was introduced in PR 1136, which also fixed it on Unix. Apparently test results on MinGW were not checked at that point, so we missed that this new test was also failing on this platform. --- ChangeLog | 2 +- library/timing.c | 8 ++++++++ 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/ChangeLog b/ChangeLog index 27c3d13b8..51ca06606 100644 --- a/ChangeLog +++ b/ChangeLog @@ -57,7 +57,7 @@ Bugfix * Fix word size check in in pk.c to not depend on MBEDTLS_HAVE_INT64. * Fix crash when calling mbedtls_ssl_cache_free() twice. Found by MilenkoMitrovic, #1104 - * Fix mbedtls_timing_alarm(0) on Unix. + * Fix mbedtls_timing_alarm(0) on Unix and MinGw. * Fix use of uninitialized memory in mbedtls_timing_get_timer when reset=1. * Fix issue in RSA key generation program programs/x509/rsa_genkey where the failure of CTR DRBG initialization lead to freeing an diff --git a/library/timing.c b/library/timing.c index de936e101..d9db5d2df 100644 --- a/library/timing.c +++ b/library/timing.c @@ -273,6 +273,14 @@ void mbedtls_set_alarm( int seconds ) { DWORD ThreadId; + if( seconds == 0 ) + { + /* No need to create a thread for this simple case. + * Also, this shorcut is more reliable at least on MinGW32 */ + mbedtls_timing_alarmed = 1; + return; + } + mbedtls_timing_alarmed = 0; alarmMs = seconds * 1000; CloseHandle( CreateThread( NULL, 0, TimerProc, NULL, 0, &ThreadId ) );