Skip to content

Commit 74720a2

Browse files
committed
Fix memory leak in openssl_sign() when passing invalid algorithm
Closes GH-18185.
1 parent 2e47442 commit 74720a2

File tree

3 files changed

+23
-0
lines changed

3 files changed

+23
-0
lines changed

NEWS

+4
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,10 @@ PHP NEWS
66
. Fixed imagecrop() overflow with rect argument with x/width y/heigh usage
77
in gdImageCrop(). (David Carlier)
88

9+
- OpenSSL:
10+
. Fix memory leak in openssl_sign() when passing invalid algorithm.
11+
(nielsdos)
12+
913
- Standard:
1014
. Fixed bug GH-18145 (php8ts crashes in php_clear_stat_cache()).
1115
(Jakub Zelenka)

ext/openssl/openssl.c

+1
Original file line numberDiff line numberDiff line change
@@ -6959,6 +6959,7 @@ PHP_FUNCTION(openssl_sign)
69596959
mdtype = php_openssl_get_evp_md_from_algo(method_long);
69606960
}
69616961
if (!mdtype) {
6962+
EVP_PKEY_free(pkey);
69626963
php_error_docref(NULL, E_WARNING, "Unknown digest algorithm");
69636964
RETURN_FALSE;
69646965
}
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)