Only call OPENSSL_init_crypto on fetch if using the default libctx

There is no point in calling OPENSSL_init_crypto() unless we are actually
going to be using the default libctx.

Fixes #20315

Reviewed-by: Dmitry Belyavskiy <beldmit@gmail.com>
Reviewed-by: Paul Dale <pauli@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/20341)
This commit is contained in:
Matt Caswell 2023-02-20 14:47:20 +00:00 committed by Pauli
parent 7e5505107a
commit 7a6a0baa59

View File

@ -502,14 +502,15 @@ int ossl_method_store_fetch(OSSL_METHOD_STORE *store,
int ret = 0;
int j, best = -1, score, optional;
#ifndef FIPS_MODULE
if (!OPENSSL_init_crypto(OPENSSL_INIT_LOAD_CONFIG, NULL))
return 0;
#endif
if (nid <= 0 || method == NULL || store == NULL)
return 0;
#ifndef FIPS_MODULE
if (ossl_lib_ctx_is_default(store->ctx)
&& !OPENSSL_init_crypto(OPENSSL_INIT_LOAD_CONFIG, NULL))
return 0;
#endif
/* This only needs to be a read lock, because the query won't create anything */
if (!ossl_property_read_lock(store))
return 0;