diff options
author | Matt Caswell <matt@openssl.org> | 2021-06-21 09:23:30 +0100 |
---|---|---|
committer | Matt Caswell <matt@openssl.org> | 2021-06-24 14:48:14 +0100 |
commit | 29aff653150c363be2d84f789a10b46d99d5cab9 (patch) | |
tree | c6aba738ee2873756bbb32419173955171e71fce /crypto/provider.c | |
parent | 352d482a2990cc04adff48aeda9c080d4a839f1e (diff) |
Add a new provider to the store only after we activate it
Rather than creating the provider, adding to the store and then activating
it, we do things the other way around, i.e. activate first and then add to
the store. This means that the activation should occur before other threads
are aware of the provider.
Reviewed-by: Paul Dale <pauli@openssl.org>
Reviewed-by: Tomas Mraz <tomas@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/15854)
Diffstat (limited to 'crypto/provider.c')
-rw-r--r-- | crypto/provider.c | 15 |
1 files changed, 12 insertions, 3 deletions
diff --git a/crypto/provider.c b/crypto/provider.c index 5aec157c1f..12336acc57 100644 --- a/crypto/provider.c +++ b/crypto/provider.c @@ -17,17 +17,26 @@ OSSL_PROVIDER *OSSL_PROVIDER_try_load(OSSL_LIB_CTX *libctx, const char *name, int retain_fallbacks) { OSSL_PROVIDER *prov = NULL; + int isnew = 0; /* Find it or create it */ - if ((prov = ossl_provider_find(libctx, name, 0)) == NULL - && (prov = ossl_provider_new(libctx, name, NULL, 0)) == NULL) - return NULL; + if ((prov = ossl_provider_find(libctx, name, 0)) == NULL) { + if ((prov = ossl_provider_new(libctx, name, NULL, 0)) == NULL) + return NULL; + isnew = 1; + } if (!ossl_provider_activate(prov, retain_fallbacks, 1)) { ossl_provider_free(prov); return NULL; } + if (isnew && !ossl_provider_add_to_store(prov)) { + ossl_provider_deactivate(prov); + ossl_provider_free(prov); + return NULL; + } + return prov; } |