THREADING: Make CRYPTO_MUTEX and CRYPTO_CONDVAR typesafe
authorHugo Landau <hlandau@openssl.org>
Thu, 8 Feb 2024 10:27:56 +0000 (10:27 +0000)
committerTomas Mraz <tomas@openssl.org>
Fri, 9 Feb 2024 13:10:17 +0000 (14:10 +0100)
There was really no need for this to be void and it made bugs very easy
to introduce accidentally, especially given that the free functions
needed to be passed a pointer to the pointer.

Also fix some bugs in the QUIC code detected immediately by this change.

.

Reviewed-by: Matt Caswell <matt@openssl.org>
Reviewed-by: Tomas Mraz <tomas@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/23519)

include/internal/quic_reactor.h
include/internal/thread_arch.h
ssl/quic/quic_impl.c
ssl/quic/quic_thread_assist.c

index 10d54ee15649dd7d340d927aeec65d557c2ae2ec..47d93eee0666547bd933dfb77f8272a64f67a43a 100644 (file)
@@ -12,6 +12,7 @@
 # include "internal/time.h"
 # include "internal/sockets.h"
 # include "internal/quic_predef.h"
+# include "internal/thread_arch.h"
 # include <openssl/bio.h>
 
 # ifndef OPENSSL_NO_QUIC
@@ -191,7 +192,7 @@ int ossl_quic_reactor_tick(QUIC_REACTOR *rtor, uint32_t flags);
 int ossl_quic_reactor_block_until_pred(QUIC_REACTOR *rtor,
                                        int (*pred)(void *arg), void *pred_arg,
                                        uint32_t flags,
-                                       CRYPTO_RWLOCK *mutex);
+                                       CRYPTO_MUTEX *mutex);
 
 # endif
 
index 1bfc0ebb3d3773e5b139f4884a6112f3d71d139e..0994433e7dc17f7771e5b6e39b126c8d18bb34f0 100644 (file)
@@ -37,8 +37,8 @@
 
 # include <openssl/crypto.h>
 
-typedef void CRYPTO_MUTEX;
-typedef void CRYPTO_CONDVAR;
+typedef struct crypto_mutex_st CRYPTO_MUTEX;
+typedef struct crypto_condvar_st CRYPTO_CONDVAR;
 
 CRYPTO_MUTEX *ossl_crypto_mutex_new(void);
 void ossl_crypto_mutex_lock(CRYPTO_MUTEX *mutex);
index de39a5c7aa750d957ff0af5d48490b601d66a891..af505d12032af6611c3b1efceda1a3918bf4cbc9 100644 (file)
@@ -453,7 +453,7 @@ SSL *ossl_quic_new(SSL_CTX *ctx)
 err:
     if (ssl_base == NULL) {
 #if defined(OPENSSL_THREADS)
-        ossl_crypto_mutex_free(qc->mutex);
+        ossl_crypto_mutex_free(&qc->mutex);
 #endif
         OPENSSL_free(qc);
     } else {
index e1de72a910a8112345ee1005ada524847daf2972..ad49781c742964b82b3e40beaaedb6bd92452ce5 100644 (file)
@@ -91,7 +91,7 @@ int ossl_quic_thread_assist_init_start(QUIC_THREAD_ASSIST *qta,
     qta->t = ossl_crypto_thread_native_start(assist_thread_main,
                                              qta, /*joinable=*/1);
     if (qta->t == NULL) {
-        ossl_crypto_condvar_free(qta->cv);
+        ossl_crypto_condvar_free(&qta->cv);
         return 0;
     }