From: Tomas Mraz Date: Tue, 26 Sep 2023 15:39:50 +0000 (+0200) Subject: Optimize out unneeded up_ref/free of EVP_CIPHER X-Git-Tag: openssl-3.2.0-beta1~165 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=8ed76c62b5d3214e807e684c06efd69c6471c800;p=thirdparty%2Fopenssl.git Optimize out unneeded up_ref/free of EVP_CIPHER Fixes #22189 Reviewed-by: Matt Caswell Reviewed-by: Paul Dale (Merged from https://github.com/openssl/openssl/pull/22198) --- diff --git a/crypto/evp/evp_enc.c b/crypto/evp/evp_enc.c index 84ce108b254..e1d3eeef641 100644 --- a/crypto/evp/evp_enc.c +++ b/crypto/evp/evp_enc.c @@ -200,7 +200,12 @@ static int evp_cipher_init_internal(EVP_CIPHER_CTX *ctx, #endif } - if (cipher->prov != NULL) { + if (!ossl_assert(cipher->prov != NULL)) { + ERR_raise(ERR_LIB_EVP, EVP_R_INITIALIZATION_ERROR); + return 0; + } + + if (cipher != ctx->fetched_cipher) { if (!EVP_CIPHER_up_ref((EVP_CIPHER *)cipher)) { ERR_raise(ERR_LIB_EVP, EVP_R_INITIALIZATION_ERROR); return 0;