[php-src] PHP-8.6: openssl: Fix memory leak by doing early salt validation
| From: | Alexander Danilov via ndossche | Date: | Tue, 29 Sep 2026 18:40:50 +0000 |
| Subject: | [php-src] PHP-8.6: openssl: Fix memory leak by doing early salt validation | ||
| Groups: | php.cvs | ||
| Request: | Send a blank email to php-cvs+get-141717@lists.php.net to get a copy of this message | ||
Author: Alexander Danilov (adapik)
Committer: ndossche (ndossche)
Date: 2026-09-29T20:40:31+02:00
Commit: https://github.com/php/php-src/commit/77bdd80927d9440d17be7dce7c06a2cc2292b40a
Raw diff: https://github.com/php/php-src/commit/77bdd80927d9440d17be7dce7c06a2cc2292b40a.diff
openssl: Fix memory leak by doing early salt validation
Closes GH-23999.
Changed paths:
M NEWS
M ext/openssl/openssl.c
Diff:
diff --git a/NEWS b/NEWS
index 18d07cc32fff..478e2291210e 100644
--- a/NEWS
+++ b/NEWS
@@ -37,6 +37,7 @@ PHP NEWS
- OpenSSL:
. Fixed stream_socket_enable_crypto() leaving the socket non-blocking
after a handshake timeout. (Ilia Alshanetsky)
+ . Fix memory leak by doing early salt validation. (adapik)
- PCNTL:
. Fixed pcntl_signal_dispatch() dropping the queued signals when it runs while
diff --git a/ext/openssl/openssl.c b/ext/openssl/openssl.c
index 5ea2a7737434..6ec8a11734a9 100644
--- a/ext/openssl/openssl.c
+++ b/ext/openssl/openssl.c
@@ -4556,6 +4556,8 @@ PHP_FUNCTION(openssl_sign)
Z_PARAM_LONG(salt_length)
ZEND_PARSE_PARAMETERS_END();
+ PHP_OPENSSL_CHECK_LONG_TO_INT(salt_length, salt_length, 6);
+
pkey = php_openssl_pkey_from_zval(key, 0, "", 0, 3);
if (pkey == NULL) {
if (!EG(exception)) {
@@ -4574,7 +4576,6 @@ PHP_FUNCTION(openssl_sign)
php_error_docref(NULL, E_WARNING, "Unknown digest algorithm");
RETURN_FALSE;
}
- PHP_OPENSSL_CHECK_LONG_TO_INT(salt_length, salt_length, 6);
md_ctx = EVP_MD_CTX_create();
size_t siglen;