summaryrefslogtreecommitdiffstats
path: root/crypto/rand
diff options
context:
space:
mode:
authorJiasheng Jiang <jiasheng@iscas.ac.cn>2022-02-15 17:45:04 +0800
committerDr. Matthias St. Pierre <matthias.st.pierre@ncp-e.com>2022-02-20 13:10:09 +0100
commiteee4287febb296afae3de9e21c5d9cbae14a9802 (patch)
tree6f1a8f36cd56102061ae7001a31918ae492faf56 /crypto/rand
parentd1ce1b5df602e4fc64bd27b65b4b1343229007af (diff)
rand: Add missing check for rand_get_global
As the potential failure of the rand_get_global(), for example fail to get lock, 'dgbl' could be NULL pointer and be dereferenced later. Therefore, it should be better to check it and return error if fails, like RAND_get0_primary() and other callers. Signed-off-by: Jiasheng Jiang <jiasheng@iscas.ac.cn> Reviewed-by: Tomas Mraz <tomas@openssl.org> Reviewed-by: Paul Dale <pauli@openssl.org> Reviewed-by: Shane Lontis <shane.lontis@oracle.com> (Merged from https://github.com/openssl/openssl/pull/17690) (cherry picked from commit 09dca557332a2187598932388ac7bd7bbf16172b)
Diffstat (limited to 'crypto/rand')
-rw-r--r--crypto/rand/rand_lib.c7
1 files changed, 7 insertions, 0 deletions
diff --git a/crypto/rand/rand_lib.c b/crypto/rand/rand_lib.c
index 8f76c8a5f0..1cb6f78296 100644
--- a/crypto/rand/rand_lib.c
+++ b/crypto/rand/rand_lib.c
@@ -529,6 +529,8 @@ static EVP_RAND_CTX *rand_new_seed(OSSL_LIB_CTX *libctx)
EVP_RAND_CTX *ctx;
char *name;
+ if (dgbl == NULL)
+ return NULL;
name = dgbl->seed_name != NULL ? dgbl->seed_name : "SEED-SRC";
rand = EVP_RAND_fetch(libctx, name, dgbl->seed_propq);
if (rand == NULL) {
@@ -560,6 +562,8 @@ static EVP_RAND_CTX *rand_new_drbg(OSSL_LIB_CTX *libctx, EVP_RAND_CTX *parent,
OSSL_PARAM params[7], *p = params;
char *name, *cipher;
+ if (dgbl == NULL)
+ return NULL;
name = dgbl->rng_name != NULL ? dgbl->rng_name : "CTR-DRBG";
rand = EVP_RAND_fetch(libctx, name, dgbl->rng_propq);
if (rand == NULL) {
@@ -759,6 +763,9 @@ static int random_conf_init(CONF_IMODULE *md, const CONF *cnf)
return 0;
}
+ if (dgbl == NULL)
+ return 0;
+
for (i = 0; i < sk_CONF_VALUE_num(elist); i++) {
cval = sk_CONF_VALUE_value(elist, i);
if (strcasecmp(cval->name, "random") == 0) {