From: Jorge Pereira Date: Thu, 6 Apr 2023 19:00:04 +0000 (-0300) Subject: Add assert to catch invalid mutex (#4960) X-Git-Tag: release_3_2_3~86 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=d9b58e56b7bd8fe0acd3a8ab08617261d70148b1;p=thirdparty%2Ffreeradius-server.git Add assert to catch invalid mutex (#4960) --- diff --git a/src/main/threads.c b/src/main/threads.c index 3553fbb91b..d5c065fc4f 100644 --- a/src/main/threads.c +++ b/src/main/threads.c @@ -253,10 +253,12 @@ static pthread_mutex_t *ssl_mutexes = NULL; static void ssl_locking_function(int mode, int n, UNUSED char const *file, UNUSED int line) { + rad_assert(ssl_mutexes[n] != NULL); + if (mode & CRYPTO_LOCK) { - pthread_mutex_lock(&(ssl_mutexes[n])); + pthread_mutex_lock(&ssl_mutexes[n]); } else { - pthread_mutex_unlock(&(ssl_mutexes[n])); + pthread_mutex_unlock(&ssl_mutexes[n]); } } #endif @@ -269,6 +271,8 @@ int tls_mutexes_init(void) #ifdef HAVE_CRYPTO_SET_LOCKING_CALLBACK int i, num; + rad_assert(ssl_mutexes == NULL); + num = CRYPTO_num_locks(); ssl_mutexes = rad_malloc(num * sizeof(pthread_mutex_t)); @@ -278,7 +282,7 @@ int tls_mutexes_init(void) } for (i = 0; i < num; i++) { - pthread_mutex_init(&(ssl_mutexes[i]), NULL); + pthread_mutex_init(&ssl_mutexes[i], NULL); } CRYPTO_set_locking_callback(ssl_locking_function); @@ -292,6 +296,8 @@ static void tls_mutexes_destroy(void) #ifdef HAVE_CRYPTO_SET_LOCKING_CALLBACK int i, num; + rad_assert(ssl_mutexes != NULL); + num = CRYPTO_num_locks(); for (i = 0; i < num; i++) {