]> git.ipfire.org Git - thirdparty/openssl.git/commitdiff
Optimize out unneeded up_ref/free of EVP_CIPHER
authorTomas Mraz <tomas@openssl.org>
Tue, 26 Sep 2023 15:39:50 +0000 (17:39 +0200)
committerTomas Mraz <tomas@openssl.org>
Thu, 5 Oct 2023 18:07:41 +0000 (20:07 +0200)
Fixes #22189

Reviewed-by: Matt Caswell <matt@openssl.org>
Reviewed-by: Paul Dale <pauli@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/22198)

(cherry picked from commit 8ed76c62b5d3214e807e684c06efd69c6471c800)

crypto/evp/evp_enc.c

index 0ebfbdaf22fe9b1051367184e40ea6dd16df6f68..fec889d2fec480049479f4db1ac6435213254224 100644 (file)
@@ -197,7 +197,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;