From a0af95f052fa734c662dfe420d3e34e6ed777ed5 Mon Sep 17 00:00:00 2001 From: Gilles Peskine Date: Tue, 10 Oct 2017 20:10:46 +0200 Subject: [PATCH] Timing: fix mbedtls_set_alarm(0) on Unix/POSIX The POSIX/Unix implementation of mbedtls_set_alarm did not set the mbedtls_timing_alarmed flag when called with 0, which was inconsistent with what the documentation implied and with the Windows behavior. --- ChangeLog | 1 + library/timing.c | 6 ++++++ 2 files changed, 7 insertions(+) diff --git a/ChangeLog b/ChangeLog index b3d4d519a..bfba279b9 100644 --- a/ChangeLog +++ b/ChangeLog @@ -9,6 +9,7 @@ Bugfix * Fix memory leak in mbedtls_ssl_set_hostname() when called multiple times. Found by projectgus and jethrogb, #836. * Fix usage help in ssl_server2 example. Found and fixed by Bei Lin. + * Fix mbedtls_timing_alarm(0) on Unix. = mbed TLS 2.6.0 branch released 2017-08-10 diff --git a/library/timing.c b/library/timing.c index a7c7ff027..4576f317d 100644 --- a/library/timing.c +++ b/library/timing.c @@ -315,6 +315,12 @@ void mbedtls_set_alarm( int seconds ) mbedtls_timing_alarmed = 0; signal( SIGALRM, sighandler ); alarm( seconds ); + if( seconds == 0 ) + { + /* alarm(0) cancelled any previous pending alarm, but the + handler won't fire, so raise the flag straight away. */ + mbedtls_timing_alarmed = 1; + } } #endif /* _WIN32 && !EFIX64 && !EFI32 */