]> git.ipfire.org Git - thirdparty/openssl.git/commitdiff
Only associate a provider with a store once it has been added to it
authorMatt Caswell <matt@openssl.org>
Mon, 21 Jun 2021 11:13:31 +0000 (12:13 +0100)
committerMatt Caswell <matt@openssl.org>
Thu, 24 Jun 2021 13:48:15 +0000 (14:48 +0100)
This means we can distinguish providers that have been added to the
store, and those which haven't yet been.

Reviewed-by: Paul Dale <pauli@openssl.org>
Reviewed-by: Tomas Mraz <tomas@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/15854)

crypto/provider_core.c

index e41c49e0ad2631dbf8d91e65c674e2fc050e9a01..b52769132ed86a0000aee80bb0fab3c014a9f046 100644 (file)
@@ -498,7 +498,6 @@ OSSL_PROVIDER *ossl_provider_new(OSSL_LIB_CTX *libctx, const char *name,
         return NULL;
 
     prov->libctx = libctx;
-    prov->store = store;
 #ifndef FIPS_MODULE
     prov->error_lib = ERR_get_next_error_library();
 #endif
@@ -530,6 +529,7 @@ int ossl_provider_add_to_store(OSSL_PROVIDER *prov, int retain_fallbacks)
         ossl_provider_free(prov);
         ret = 0;
     }
+    prov->store = store;
     if (!retain_fallbacks)
         store->use_fallbacks = 0;
     CRYPTO_THREAD_unlock(store->lock);
@@ -1102,7 +1102,6 @@ static int provider_activate_fallbacks(struct provider_store_st *store)
         if (prov == NULL)
             goto err;
         prov->libctx = store->libctx;
-        prov->store = store;
 #ifndef FIPS_MODULE
         prov->error_lib = ERR_get_next_error_library();
 #endif
@@ -1113,8 +1112,12 @@ static int provider_activate_fallbacks(struct provider_store_st *store)
          * we try to avoid calling a user callback while holding a lock.
          * However, fallbacks are never third party providers so we accept this.
          */
-        if (provider_activate(prov, 0, 0) < 0
-                || sk_OSSL_PROVIDER_push(store->providers, prov) == 0) {
+        if (provider_activate(prov, 0, 0) < 0) {
+            ossl_provider_free(prov);
+            goto err;
+        }
+        prov->store = store;
+        if (sk_OSSL_PROVIDER_push(store->providers, prov) == 0) {
             ossl_provider_free(prov);
             goto err;
         }