summaryrefslogtreecommitdiffstats
path: root/crypto/context.c
diff options
context:
space:
mode:
authorTomas Mraz <tomas@openssl.org>2021-12-16 16:06:34 +0100
committerTomas Mraz <tomas@openssl.org>2021-12-17 18:00:10 +0100
commitceb5a16915f013ea1f6dd8c86ab3761b25e1c10d (patch)
tree5a55310d49e0715f298fffbd0719e27c7ac6daca /crypto/context.c
parentc526c510fadc0e25a93c1069b7362f1feab5ab28 (diff)
context_init: Fix cleanup in error handling
Also never use OSSL_LIB_CTX_free() on incompletely initialized context. Fixes #17291 Reviewed-by: Matt Caswell <matt@openssl.org> (Merged from https://github.com/openssl/openssl/pull/17294) (cherry picked from commit 7ca3bf792a4a085e6f2426ad51a41fca4d0b1b8c)
Diffstat (limited to 'crypto/context.c')
-rw-r--r--crypto/context.c10
1 files changed, 5 insertions, 5 deletions
diff --git a/crypto/context.c b/crypto/context.c
index bba8e4208b..a05009a3ef 100644
--- a/crypto/context.c
+++ b/crypto/context.c
@@ -93,10 +93,8 @@ static int context_init(OSSL_LIB_CTX *ctx)
exdata_done = 1;
if (!ossl_crypto_new_ex_data_ex(ctx, CRYPTO_EX_INDEX_OSSL_LIB_CTX, NULL,
- &ctx->data)) {
- ossl_crypto_cleanup_all_ex_data_int(ctx);
+ &ctx->data))
goto err;
- }
/* Everything depends on properties, so we also pre-initialise that */
if (!ossl_property_parse_init(ctx))
@@ -106,9 +104,11 @@ static int context_init(OSSL_LIB_CTX *ctx)
err:
if (exdata_done)
ossl_crypto_cleanup_all_ex_data_int(ctx);
+ for (i = 0; i < OSSL_LIB_CTX_MAX_INDEXES; i++)
+ CRYPTO_THREAD_lock_free(ctx->index_locks[i]);
CRYPTO_THREAD_lock_free(ctx->oncelock);
CRYPTO_THREAD_lock_free(ctx->lock);
- ctx->lock = NULL;
+ memset(ctx, '\0', sizeof(*ctx));
return 0;
}
@@ -189,7 +189,7 @@ OSSL_LIB_CTX *OSSL_LIB_CTX_new(void)
OSSL_LIB_CTX *ctx = OPENSSL_zalloc(sizeof(*ctx));
if (ctx != NULL && !context_init(ctx)) {
- OSSL_LIB_CTX_free(ctx);
+ OPENSSL_free(ctx);
ctx = NULL;
}
return ctx;