diff options
author | Richard Levitte <levitte@openssl.org> | 2022-10-16 07:52:09 +0200 |
---|---|---|
committer | Richard Levitte <levitte@openssl.org> | 2022-10-25 13:09:40 +0200 |
commit | 840a82982976a0ee4336a3ee0dc4f389aac14b01 (patch) | |
tree | ae3ea6a54b0309be7562e991189e2097aa9876b5 | |
parent | 9cbd2e1098caea4b327b06a1e1e353a58793b50c (diff) |
Finer grained error records for provider load/init failures
When a provider is activated, these three cases would record that the
provider init function failed (implying that it was called):
- failure to load the provider module (in case it's a dynamically
loadable module)
- the init function not being present (i.e. being NULL)
- the init function being called and returning an error indication
(i.e. returning a false value)
This is confusing.
Separating the three cases so that they record different errors will
make it easier to determine causes of failure.
Reviewed-by: Dmitry Belyavskiy <beldmit@gmail.com>
Reviewed-by: Matt Caswell <matt@openssl.org>
Reviewed-by: Tomas Mraz <tomas@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/19419)
(cherry picked from commit 2d23ba14630551ee347acafcab81fa1a290c6504)
-rw-r--r-- | crypto/provider_core.c | 26 |
1 files changed, 19 insertions, 7 deletions
diff --git a/crypto/provider_core.c b/crypto/provider_core.c index 7e62e1bfea..7a12328121 100644 --- a/crypto/provider_core.c +++ b/crypto/provider_core.c @@ -907,16 +907,28 @@ static int provider_init(OSSL_PROVIDER *prov) OPENSSL_free(allocated_load_dir); } - if (prov->module != NULL) - prov->init_function = (OSSL_provider_init_fn *) - DSO_bind_func(prov->module, "OSSL_provider_init"); + if (prov->module == NULL) { + /* DSO has already recorded errors, this is just a tracepoint */ + ERR_raise_data(ERR_LIB_CRYPTO, ERR_R_DSO_LIB, + "name=%s", prov->name); + goto end; + } + + prov->init_function = (OSSL_provider_init_fn *) + DSO_bind_func(prov->module, "OSSL_provider_init"); #endif } - /* Call the initialise function for the provider. */ - if (prov->init_function == NULL - || !prov->init_function((OSSL_CORE_HANDLE *)prov, core_dispatch, - &provider_dispatch, &tmp_provctx)) { + /* Check for and call the initialise function for the provider. */ + if (prov->init_function == NULL) { + ERR_raise_data(ERR_LIB_CRYPTO, ERR_R_UNSUPPORTED, + "name=%s, provider has no provider init function", + prov->name); + goto end; + } + + if (!prov->init_function((OSSL_CORE_HANDLE *)prov, core_dispatch, + &provider_dispatch, &tmp_provctx)) { ERR_raise_data(ERR_LIB_CRYPTO, ERR_R_INIT_FAIL, "name=%s", prov->name); goto end; |