From c7b6fa2931f9da69ba9235ccd2283c1a57730983 Mon Sep 17 00:00:00 2001 From: David Garske Date: Tue, 8 Aug 2023 13:58:38 -0700 Subject: [PATCH] Return codes and missed srtp. --- wolfcrypt/src/wc_port.c | 26 +++++++++++++++----------- wolfssl/test.h | 8 +++++--- 2 files changed, 20 insertions(+), 14 deletions(-) diff --git a/wolfcrypt/src/wc_port.c b/wolfcrypt/src/wc_port.c index 54eb27f25..e39f6ad9e 100644 --- a/wolfcrypt/src/wc_port.c +++ b/wolfcrypt/src/wc_port.c @@ -3705,7 +3705,7 @@ char* mystrnstr(const char* s1, const char* s2, unsigned int n) if (pthread_mutex_init(&cond->mutex, NULL) != 0) return MEMORY_E; if (pthread_cond_init(&cond->cond, NULL) != 0) { - pthread_mutex_destroy(&cond->mutex); + (void)pthread_mutex_destroy(&cond->mutex); return MEMORY_E; } return 0; @@ -3716,8 +3716,8 @@ char* mystrnstr(const char* s1, const char* s2, unsigned int n) if (cond == NULL) return BAD_FUNC_ARG; - pthread_mutex_destroy(&cond->mutex); - pthread_cond_destroy(&cond->cond); + (void)pthread_mutex_destroy(&cond->mutex); + (void)pthread_cond_destroy(&cond->cond); return 0; } @@ -3726,10 +3726,12 @@ char* mystrnstr(const char* s1, const char* s2, unsigned int n) if (cond == NULL) return BAD_FUNC_ARG; - pthread_mutex_lock(&cond->mutex); - pthread_cond_signal(&cond->cond); - pthread_mutex_unlock(&cond->mutex); - return 0; + if (pthread_mutex_lock(&cond->mutex) == 0) { + (void)pthread_cond_signal(&cond->cond); + (void)pthread_mutex_unlock(&cond->mutex); + return 0; + } + return BAD_MUTEX_E; } int wolfSSL_CondWait(COND_TYPE* cond) @@ -3737,10 +3739,12 @@ char* mystrnstr(const char* s1, const char* s2, unsigned int n) if (cond == NULL) return BAD_FUNC_ARG; - pthread_mutex_lock(&cond->mutex); - pthread_cond_wait(&cond->cond, &cond->mutex); - pthread_mutex_unlock(&cond->mutex); - return 0; + if (pthread_mutex_lock(&cond->mutex) == 0) { + (void)pthread_cond_wait(&cond->cond, &cond->mutex); + (void)pthread_mutex_unlock(&cond->mutex); + return 0; + } + return BAD_MUTEX_E; } #else /* Apple style dispatch semaphore */ diff --git a/wolfssl/test.h b/wolfssl/test.h index f19cfbd3f..e468e7bae 100644 --- a/wolfssl/test.h +++ b/wolfssl/test.h @@ -691,10 +691,12 @@ static WC_INLINE void srtp_helper_init(srtp_test_helper *srtp) static WC_INLINE void srtp_helper_get_ekm(srtp_test_helper *srtp, uint8_t **ekm, size_t *size) { - if (srtp->server_srtp_ekm == NULL) - THREAD_CHECK_RET(wolfSSL_CondWait(&srtp->cond, &srtp->mutex)); - THREAD_CHECK_RET(wc_LockMutex(&srtp->mutex)); + if (srtp->server_srtp_ekm == NULL) { + THREAD_CHECK_RET(wc_UnLockMutex(&srtp->mutex)); + THREAD_CHECK_RET(wolfSSL_CondWait(&srtp->cond)); + THREAD_CHECK_RET(wc_LockMutex(&srtp->mutex)); + } *ekm = srtp->server_srtp_ekm; *size = srtp->server_srtp_ekm_size;