Skip to content

Commit 4c043d8

Browse files
committed
Merge branch 'PHP-8.3' into PHP-8.4
* PHP-8.3: phar: Fix memory leak when openssl polyfill returns garbage
2 parents 4289bda + 020bbea commit 4c043d8

File tree

3 files changed

+38
-1
lines changed

3 files changed

+38
-1
lines changed

NEWS

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ PHP NEWS
5959
(nielsdos)
6060
. Fix potential buffer length truncation due to usage of type int instead
6161
of type size_t. (Girgias)
62+
. Fix memory leak when openssl polyfill returns garbage. (nielsdos)
6263

6364
- Random:
6465
. Fix Randomizer::__serialize() w.r.t. INDIRECTs. (nielsdos)
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 & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1520,7 +1520,6 @@ static int phar_call_openssl_signverify(int is_sign, php_stream *fp, zend_off_t
15201520
zval_ptr_dtor_str(&zp[2]);
15211521

15221522
switch (Z_TYPE(retval)) {
1523-
default:
15241523
case IS_LONG:
15251524
zval_ptr_dtor(&zp[1]);
15261525
if (1 == Z_LVAL(retval)) {
@@ -1532,6 +1531,9 @@ static int phar_call_openssl_signverify(int is_sign, php_stream *fp, zend_off_t
15321531
*signature_len = Z_STRLEN(zp[1]);
15331532
zval_ptr_dtor(&zp[1]);
15341533
return SUCCESS;
1534+
default:
1535+
zval_ptr_dtor(&retval);
1536+
ZEND_FALLTHROUGH;
15351537
case IS_FALSE:
15361538
zval_ptr_dtor(&zp[1]);
15371539
return FAILURE;

0 commit comments

Comments
 (0)