summaryrefslogtreecommitdiffstats
path: root/crypto/rand
diff options
context:
space:
mode:
authorRich Salz <rsalz@akamai.com>2021-02-18 15:31:56 -0500
committerPauli <ppzgs1@gmail.com>2021-03-14 15:33:34 +1000
commitcd3f8c1b11b0b9f4163bc8c62cbae38aec1b4030 (patch)
treede59d50b2ff9b2bd73a1ebf08eedf78d8ba44aa3 /crypto/rand
parentf62846b703d163265176fe960ec7d087b4c3fa96 (diff)
Always check CRYPTO_LOCK_{read,write}_lock
Some functions that lock things are void, so we just return early. Also make ossl_namemap_empty return 0 on error. Updated the docs, and added some code to ossl_namemap_stored() to handle the failure, and updated the tests to allow for failure. Fixes: #14230 Reviewed-by: Shane Lontis <shane.lontis@oracle.com> Reviewed-by: Paul Dale <pauli@openssl.org> (Merged from https://github.com/openssl/openssl/pull/14238)
Diffstat (limited to 'crypto/rand')
-rw-r--r--crypto/rand/rand_lib.c12
1 files changed, 9 insertions, 3 deletions
diff --git a/crypto/rand/rand_lib.c b/crypto/rand/rand_lib.c
index e248d5753a..3cd34198c1 100644
--- a/crypto/rand/rand_lib.c
+++ b/crypto/rand/rand_lib.c
@@ -163,7 +163,8 @@ int RAND_set_rand_method(const RAND_METHOD *meth)
if (!RUN_ONCE(&rand_init, do_rand_init))
return 0;
- CRYPTO_THREAD_write_lock(rand_meth_lock);
+ if (!CRYPTO_THREAD_write_lock(rand_meth_lock))
+ return 0;
# ifndef OPENSSL_NO_ENGINE
ENGINE_finish(funct_ref);
funct_ref = NULL;
@@ -180,7 +181,8 @@ const RAND_METHOD *RAND_get_rand_method(void)
if (!RUN_ONCE(&rand_init, do_rand_init))
return NULL;
- CRYPTO_THREAD_write_lock(rand_meth_lock);
+ if (!CRYPTO_THREAD_write_lock(rand_meth_lock))
+ return NULL;
if (default_RAND_meth == NULL) {
# ifndef OPENSSL_NO_ENGINE
ENGINE *e;
@@ -220,7 +222,11 @@ int RAND_set_rand_engine(ENGINE *engine)
return 0;
}
}
- CRYPTO_THREAD_write_lock(rand_engine_lock);
+ if (!CRYPTO_THREAD_write_lock(rand_engine_lock)) {
+ ENGINE_finish(engine);
+ return 0;
+ }
+
/* This function releases any prior ENGINE so call it first */
RAND_set_rand_method(tmp_meth);
funct_ref = engine;