fuzz/fuzz_rand.c: Add check for OSSL_LIB_CTX_new
authorJiasheng Jiang <jiasheng@iscas.ac.cn>
Mon, 21 Feb 2022 02:10:23 +0000 (10:10 +0800)
committerTomas Mraz <tomas@openssl.org>
Mon, 28 Feb 2022 11:15:41 +0000 (12:15 +0100)
As the potential failure of the OPENSSL_zalloc(), the OSSL_LIB_CTX_new()
could return NULL.
Therefore, it should be better to check it and return error if fails in
order to guarantee the success of the initialization.

Signed-off-by: Jiasheng Jiang <jiasheng@iscas.ac.cn>
Reviewed-by: Paul Dale <pauli@openssl.org>
Reviewed-by: Tomas Mraz <tomas@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/17738)

fuzz/fuzz_rand.c

index 5bd343d8ae999a078aceab437dcaae628d9cbc11..d71dfd7a3c64d70431b65ac1d407706f52fcaf10 100644 (file)
@@ -146,6 +146,8 @@ static int fuzz_rand_provider_init(const OSSL_CORE_HANDLE *handle,
                                    const OSSL_DISPATCH **out, void **provctx)
 {
     *provctx = OSSL_LIB_CTX_new();
+    if (*provctx == NULL)
+        return 0;
     *out = fuzz_rand_method;
     return 1;
 }