From de896ebd2677ab6873cc5e3b4bb57741bba53a00 Mon Sep 17 00:00:00 2001 From: Gilles Peskine Date: Tue, 10 Oct 2017 20:10:46 +0200 Subject: [PATCH] Timing: fix set_alarm(0) on Unix/POSIX The POSIX/Unix implementation of set_alarm did not set the 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 7903fc741..8b11c181f 100644 --- a/ChangeLog +++ b/ChangeLog @@ -43,6 +43,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. Changes * Extend cert_write example program by options to set the CRT version diff --git a/library/timing.c b/library/timing.c index 50410df01..6e7f93fe2 100644 --- a/library/timing.c +++ b/library/timing.c @@ -318,6 +318,12 @@ void set_alarm( int seconds ) 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. */ + alarmed = 1; + } } void m_sleep( int milliseconds )