Fix memory leak in php_openssl_pkey_from_zval()

Closes GH-16691.
This commit is contained in:
Niels Dossche 2024-11-03 21:18:34 +01:00
parent 2f4f09f7e6
commit 994e866cf2
No known key found for this signature in database
GPG key ID: B8A8AD166DF0E2E5
3 changed files with 25 additions and 0 deletions

1
NEWS
View file

@ -11,6 +11,7 @@ PHP NEWS
- OpenSSL:
. Prevent unexpected array entry conversion when reading key. (nielsdos)
. Fix various memory leaks related to openssl exports. (nielsdos)
. Fix memory leak in php_openssl_pkey_from_zval(). (nielsdos)
- PDO:
. Fixed memory leak of `setFetchMode()`. (SakiTakamachi)

View file

@ -3533,6 +3533,7 @@ static EVP_PKEY *php_openssl_pkey_from_zval(
} else {
ZVAL_COPY(&tmp, zphrase);
if (!try_convert_to_string(&tmp)) {
zval_ptr_dtor(&tmp);
return NULL;
}

View file

@ -0,0 +1,23 @@
--TEST--
php_openssl_pkey_from_zval memory leak
--EXTENSIONS--
openssl
--FILE--
<?php
class StrFail {
public function __toString(): string {
throw new Error('create a leak');
}
}
$key = ["", new StrFail];
try {
openssl_pkey_export_to_file($key, "doesnotmatter");
} catch (Error $e) {
echo $e->getMessage(), "\n";
}
?>
--EXPECT--
create a leak