From d59784e6468e28fa358b63bab1ddc49c1fea265e Mon Sep 17 00:00:00 2001 From: Kareem Abuobeid Date: Wed, 30 Sep 2020 14:21:00 -0700 Subject: [PATCH] Fix issues found by -fsanitize=thread. --- src/crl.c | 10 ++++++++++ tests/api.c | 12 ++++++++---- wolfssl/wolfcrypt/wc_port.h | 7 ++++--- 3 files changed, 22 insertions(+), 7 deletions(-) diff --git a/src/crl.c b/src/crl.c index 7f4949df8..75861887b 100644 --- a/src/crl.c +++ b/src/crl.c @@ -1099,7 +1099,17 @@ static void* DoMonitor(void* arg) } if (FD_ISSET(crl->mfd, &readfds)) { + word64 r64; + int rlen; + WOLFSSL_MSG("got custom shutdown event, breaking out"); + + /* read out the bytes written to the event to clean up */ + rlen = (int) read(crl->mfd, &r64, sizeof(r64)); + if (rlen < 0) { + WOLFSSL_MSG("read custom event failure"); + } + break; } diff --git a/tests/api.c b/tests/api.c index 0deca96df..ebdcd3276 100644 --- a/tests/api.c +++ b/tests/api.c @@ -27490,10 +27490,11 @@ static void test_wolfSSL_either_side(void) XMEMSET(&client_cb, 0, sizeof(callback_functions)); XMEMSET(&server_cb, 0, sizeof(callback_functions)); - /* Use same CTX for both client and server */ + /* Use different CTX for client and server */ client_cb.ctx = wolfSSL_CTX_new(wolfSSLv23_method()); AssertNotNull(client_cb.ctx); - server_cb.ctx = client_cb.ctx; + server_cb.ctx = wolfSSL_CTX_new(wolfSSLv23_method()); + AssertNotNull(server_cb.ctx); /* we are responsible for free'ing WOLFSSL_CTX */ server_cb.isSharedCtx = client_cb.isSharedCtx = 1; @@ -27511,6 +27512,7 @@ static void test_wolfSSL_either_side(void) #endif wolfSSL_CTX_free(client_cb.ctx); + wolfSSL_CTX_free(server_cb.ctx); FreeTcpReady(&ready); #ifndef SINGLE_THREADED @@ -27558,10 +27560,11 @@ static void test_wolfSSL_DTLS_either_side(void) XMEMSET(&client_cb, 0, sizeof(callback_functions)); XMEMSET(&server_cb, 0, sizeof(callback_functions)); - /* Use same CTX for both client and server */ + /* Use different CTX for client and server */ client_cb.ctx = wolfSSL_CTX_new(wolfDTLS_method()); AssertNotNull(client_cb.ctx); - server_cb.ctx = client_cb.ctx; + server_cb.ctx = wolfSSL_CTX_new(wolfDTLS_method()); + AssertNotNull(server_cb.ctx); /* we are responsible for free'ing WOLFSSL_CTX */ server_cb.isSharedCtx = client_cb.isSharedCtx = 1; @@ -27579,6 +27582,7 @@ static void test_wolfSSL_DTLS_either_side(void) #endif wolfSSL_CTX_free(client_cb.ctx); + wolfSSL_CTX_free(server_cb.ctx); FreeTcpReady(&ready); #ifndef SINGLE_THREADED diff --git a/wolfssl/wolfcrypt/wc_port.h b/wolfssl/wolfcrypt/wc_port.h index b63c1a603..4a28f54fa 100644 --- a/wolfssl/wolfcrypt/wc_port.h +++ b/wolfssl/wolfcrypt/wc_port.h @@ -836,11 +836,12 @@ WOLFSSL_API int wolfCrypt_Cleanup(void); #endif #endif #if !defined(XGMTIME) && !defined(TIME_OVERRIDES) - #if defined(WOLFSSL_GMTIME) || !defined(HAVE_GMTIME_R) || defined(WOLF_C99) - #define XGMTIME(c, t) gmtime((c)) - #else + /* Always use gmtime_r if available. */ + #if defined(HAVE_GMTIME_R) #define XGMTIME(c, t) gmtime_r((c), (t)) #define NEED_TMP_TIME + #else + #define XGMTIME(c, t) gmtime((c)) #endif #endif #if !defined(XVALIDATE_DATE) && !defined(HAVE_VALIDATE_DATE)