From 556ec779512b3851970fedf0a6769bddf719305b Mon Sep 17 00:00:00 2001 From: ndossche Date: Tue, 20 Jan 2026 15:20:11 +0100 Subject: [PATCH] Fix memory leaks in openssl_pkcs7_encrypt() when push fails --- ext/openssl/openssl.c | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/ext/openssl/openssl.c b/ext/openssl/openssl.c index 65e4b7b56d3..c99ce2931fd 100644 --- a/ext/openssl/openssl.c +++ b/ext/openssl/openssl.c @@ -5849,7 +5849,10 @@ PHP_FUNCTION(openssl_pkcs7_encrypt) goto clean_exit; } } - sk_X509_push(recipcerts, cert); + if (sk_X509_push(recipcerts, cert) <= 0) { + X509_free(cert); + goto clean_exit; + } } ZEND_HASH_FOREACH_END(); } else { /* a single certificate */ @@ -5870,7 +5873,10 @@ PHP_FUNCTION(openssl_pkcs7_encrypt) goto clean_exit; } } - sk_X509_push(recipcerts, cert); + if (sk_X509_push(recipcerts, cert) <= 0) { + X509_free(cert); + goto clean_exit; + } } /* sanity check the cipher */