Skip to content

Commit 41d6d36

Browse files
committed
Merge branch 'PHP-8.5'
* PHP-8.5: phar: Fix memory leak when openssl polyfill returns garbage
2 parents 5eec4d8 + 90eabf5 commit 41d6d36

File tree

2 files changed

+37
-0
lines changed

2 files changed

+37
-0
lines changed
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
--TEST--
2+
openssl_sign() polyfill with wrong return value
3+
--EXTENSIONS--
4+
phar
5+
--SKIPIF--
6+
<?php
7+
if (getenv('SKIP_SLOW_TESTS')) die('skip');
8+
if (function_exists('openssl_sign')) die('skip requires openssl disabled for mocking purposes');
9+
?>
10+
--INI--
11+
phar.require_hash=0
12+
--FILE--
13+
<?php
14+
$fname = __DIR__ . '/' . basename(__FILE__, '.php') . '.tar';
15+
16+
function openssl_sign() {
17+
return str_repeat('foobar', random_int(1, 1));
18+
}
19+
20+
$phar = new PharData($fname);
21+
$phar->setSignatureAlgorithm(Phar::OPENSSL, "randomcrap");
22+
try {
23+
$phar->addEmptyDir('blah');
24+
} catch (PharException $e) {
25+
echo $e->getMessage();
26+
}
27+
28+
?>
29+
--CLEAN--
30+
<?php
31+
@unlink(__DIR__ . '/' . basename(__FILE__, '.clean.php') . '.tar');
32+
?>
33+
--EXPECTF--
34+
phar error: unable to write signature to tar-based phar: unable to write phar "%s" with requested openssl signature

ext/phar/util.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1464,6 +1464,9 @@ static zend_result phar_call_openssl_signverify(bool is_sign, php_stream *fp, ze
14641464
*signature_len = Z_STRLEN(zp[1]);
14651465
zval_ptr_dtor(&zp[1]);
14661466
return SUCCESS;
1467+
default:
1468+
zval_ptr_dtor(&retval);
1469+
ZEND_FALLTHROUGH;
14671470
case IS_FALSE:
14681471
default:
14691472
zval_ptr_dtor(&zp[1]);

0 commit comments

Comments
 (0)