From 8f4cddbc903a402abb9f39c2e220ee3858188655 Mon Sep 17 00:00:00 2001 From: Pauli Date: Tue, 23 Mar 2021 10:59:34 +1000 Subject: rand: fix coverity 1473636: data race condition Reviewed-by: Tomas Mraz (Merged from https://github.com/openssl/openssl/pull/14651) --- crypto/rand/rand_lib.c | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) (limited to 'crypto') diff --git a/crypto/rand/rand_lib.c b/crypto/rand/rand_lib.c index 318540cff0..f6c5bc15ee 100644 --- a/crypto/rand/rand_lib.c +++ b/crypto/rand/rand_lib.c @@ -158,7 +158,8 @@ int RAND_poll(void) } # ifndef OPENSSL_NO_DEPRECATED_3_0 -int RAND_set_rand_method(const RAND_METHOD *meth) +static int rand_set_rand_method_internal(const RAND_METHOD *meth, + ossl_unused ENGINE *e) { if (!RUN_ONCE(&rand_init, do_rand_init)) return 0; @@ -167,13 +168,18 @@ int RAND_set_rand_method(const RAND_METHOD *meth) return 0; # ifndef OPENSSL_NO_ENGINE ENGINE_finish(funct_ref); - funct_ref = NULL; + funct_ref = e; # endif default_RAND_meth = meth; CRYPTO_THREAD_unlock(rand_meth_lock); return 1; } +int RAND_set_rand_method(const RAND_METHOD *meth) +{ + return rand_set_rand_method_internal(meth, NULL); +} + const RAND_METHOD *RAND_get_rand_method(void) { const RAND_METHOD *tmp_meth = NULL; @@ -228,8 +234,7 @@ int RAND_set_rand_engine(ENGINE *engine) } /* This function releases any prior ENGINE so call it first */ - RAND_set_rand_method(tmp_meth); - funct_ref = engine; + rand_set_rand_method_internal(tmp_meth, engine); CRYPTO_THREAD_unlock(rand_engine_lock); return 1; } -- cgit v1.2.3