summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMatt Caswell <matt@openssl.org>2022-05-27 11:07:37 +0100
committerMatt Caswell <matt@openssl.org>2022-06-02 10:46:29 +0100
commit13bc9889cb2a19613397fd5f26ee60f2b031432b (patch)
treea6fa4ec73b66629c40d71fbc01bfad9d54fc619a
parentcf022e7dc19a058c9674525a710038b0a2254653 (diff)
Don't call ossl_provider_free() without first setting refcnt
The function ossl_provider_free() decrements the refcnt of the provider and frees it if it has reached 0. This only works if the refcnt has already been initialised. We must only call ossl_provider_free() after this initialisation - otherwise it will fail to free the provider correctly. Addresses the issue mentioned here: https://github.com/openssl/openssl/pull/18355#issuecomment-1138741857 Reviewed-by: Tomas Mraz <tomas@openssl.org> Reviewed-by: Paul Dale <pauli@openssl.org> (Merged from https://github.com/openssl/openssl/pull/18417) (cherry picked from commit c4ed6f6f0ee700e0473def049659061dd52fd3fc)
-rw-r--r--crypto/provider_core.c11
1 files changed, 9 insertions, 2 deletions
diff --git a/crypto/provider_core.c b/crypto/provider_core.c
index 325382516f..04c78a6b98 100644
--- a/crypto/provider_core.c
+++ b/crypto/provider_core.c
@@ -458,7 +458,15 @@ static OSSL_PROVIDER *provider_new(const char *name,
#ifndef HAVE_ATOMICS
|| (prov->refcnt_lock = CRYPTO_THREAD_lock_new()) == NULL
#endif
- || (prov->opbits_lock = CRYPTO_THREAD_lock_new()) == NULL
+ ) {
+ OPENSSL_free(prov);
+ ERR_raise(ERR_LIB_CRYPTO, ERR_R_MALLOC_FAILURE);
+ return NULL;
+ }
+
+ prov->refcnt = 1; /* 1 One reference to be returned */
+
+ if ((prov->opbits_lock = CRYPTO_THREAD_lock_new()) == NULL
|| (prov->flag_lock = CRYPTO_THREAD_lock_new()) == NULL
|| (prov->name = OPENSSL_strdup(name)) == NULL
|| (prov->parameters = sk_INFOPAIR_deep_copy(parameters,
@@ -469,7 +477,6 @@ static OSSL_PROVIDER *provider_new(const char *name,
return NULL;
}
- prov->refcnt = 1; /* 1 One reference to be returned */
prov->init_function = init_function;
return prov;