diff options
author | Pauli <ppzgs1@gmail.com> | 2021-03-23 10:59:34 +1000 |
---|---|---|
committer | Pauli <pauli@openssl.org> | 2021-03-26 08:41:32 +1000 |
commit | 8f4cddbc903a402abb9f39c2e220ee3858188655 (patch) | |
tree | 0faf4612ad66224a52cd69f7da58072b25e05489 | |
parent | 9aa4be691f5c73eb3c68606d824c104550c053f7 (diff) |
rand: fix coverity 1473636: data race condition
Reviewed-by: Tomas Mraz <tomas@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/14651)
-rw-r--r-- | crypto/rand/rand_lib.c | 13 |
1 files changed, 9 insertions, 4 deletions
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; } |