Skip to content

Commit a39725b

Browse files
committed
Merge branch 'PHP-8.4'
* PHP-8.4: Fix memory leak in openssl_sign() when passing invalid algorithm
2 parents c10afa9 + d689ff6 commit a39725b

File tree

2 files changed

+19
-0
lines changed

2 files changed

+19
-0
lines changed

ext/openssl/openssl.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3968,6 +3968,7 @@ PHP_FUNCTION(openssl_sign)
39683968
mdtype = php_openssl_get_evp_md_from_algo(method_long);
39693969
}
39703970
if (!mdtype && (!can_default_digest || method_long != 0)) {
3971+
EVP_PKEY_free(pkey);
39713972
php_error_docref(NULL, E_WARNING, "Unknown digest algorithm");
39723973
RETURN_FALSE;
39733974
}
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
--TEST--
2+
openssl_sign: invalid algorithm
3+
--EXTENSIONS--
4+
openssl
5+
--FILE--
6+
<?php
7+
$dir = __DIR__;
8+
$file_pub = $dir . '/bug37820cert.pem';
9+
$file_key = $dir . '/bug37820key.pem';
10+
11+
$priv_key = file_get_contents($file_key);
12+
$priv_key_id = openssl_get_privatekey($priv_key);
13+
14+
$data = "some custom data";
15+
openssl_sign($data, $signature, $priv_key_id, "invalid algo");
16+
?>
17+
--EXPECTF--
18+
Warning: openssl_sign(): Unknown digest algorithm in %s on line %d

0 commit comments

Comments
 (0)