]> git.ipfire.org Git - thirdparty/openssl.git/commitdiff
Fix memory leak on EVP_CIPHER_param_to_asn1 failure
author77tiann <27392025k@gmail.com>
Thu, 31 Jul 2025 00:47:06 +0000 (17:47 -0700)
committerTomas Mraz <tomas@openssl.org>
Mon, 11 Aug 2025 14:55:03 +0000 (16:55 +0200)
When EVP_CIPHER_param_to_asn1() fails, xalg->parameter was not freed,
leading to a memory leak. This patch adds proper cleanup for that case.
CLA: trivial

Signed-off-by: 77tiann <27392025k@gmail.com>
Reviewed-by: Paul Dale <ppzgs1@gmail.com>
Reviewed-by: Dmitry Belyavskiy <beldmit@gmail.com>
Reviewed-by: Tomas Mraz <tomas@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/28131)

(cherry picked from commit bda2473a44e4534c3c640ce89a0971874165c6df)

crypto/pkcs7/pk7_doit.c

index 9fa215a62846f37db4cf991bd185a5bba69fc6b8..f2f1ce365ece25da24dce255ce71dcf3a8db0b74 100644 (file)
@@ -361,8 +361,11 @@ BIO *PKCS7_dataInit(PKCS7 *p7, BIO *bio)
                 if (xalg->parameter == NULL)
                     goto err;
             }
-            if (EVP_CIPHER_param_to_asn1(ctx, xalg->parameter) <= 0)
+            if (EVP_CIPHER_param_to_asn1(ctx, xalg->parameter) <= 0) {
+                ASN1_TYPE_free(xalg->parameter);
+                xalg->parameter = NULL;
                 goto err;
+            }
         }
 
         /* Lets do the pub key stuff :-) */