diff options
author | Matt Caswell <matt@openssl.org> | 2023-08-11 11:22:02 +0100 |
---|---|---|
committer | Matt Caswell <matt@openssl.org> | 2023-08-15 14:50:37 +0100 |
commit | 3d254b31344e82b8f10fda8bab196757a377eb63 (patch) | |
tree | 06d520ff39554546c624c9793eda0dbb6b1114f7 /crypto | |
parent | 643f542a89bee93e043d0899b2a1ca700d1cc418 (diff) | |
download | openssl-3d254b31344e82b8f10fda8bab196757a377eb63.tar.gz |
Fix a leak in an error path in OSSL_DECODER_CTX_new_for_pkey()
Found via the reproducible error injection in #21668
Reviewed-by: Tomas Mraz <tomas@openssl.org>
Reviewed-by: Tom Cosgrove <tom.cosgrove@arm.com>
(Merged from https://github.com/openssl/openssl/pull/21723)
Diffstat (limited to 'crypto')
-rw-r--r-- | crypto/encode_decode/decoder_pkey.c | 10 |
1 files changed, 8 insertions, 2 deletions
diff --git a/crypto/encode_decode/decoder_pkey.c b/crypto/encode_decode/decoder_pkey.c index d00ec75bea..acb061c26a 100644 --- a/crypto/encode_decode/decoder_pkey.c +++ b/crypto/encode_decode/decoder_pkey.c @@ -835,12 +835,18 @@ OSSL_DECODER_CTX_new_for_pkey(EVP_PKEY **pkey, newcache->template = ctx; if (!CRYPTO_THREAD_write_lock(cache->lock)) { + ctx = NULL; ERR_raise(ERR_LIB_OSSL_DECODER, ERR_R_CRYPTO_LIB); - return NULL; + goto err; } res = lh_DECODER_CACHE_ENTRY_retrieve(cache->hashtable, &cacheent); if (res == NULL) { - lh_DECODER_CACHE_ENTRY_insert(cache->hashtable, newcache); + (void)lh_DECODER_CACHE_ENTRY_insert(cache->hashtable, newcache); + if (lh_DECODER_CACHE_ENTRY_error(cache->hashtable)) { + ctx = NULL; + ERR_raise(ERR_LIB_OSSL_DECODER, ERR_R_CRYPTO_LIB); + goto err; + } } else { /* * We raced with another thread to construct this and lost. Free |