Skip to content

Commit ebe5e29

Browse files
committed
uri: Fix double-free when assigning $errors by reference fails
`ZEND_TRY_ASSIGN_REF_ARR()` apparently consumes the to-be-assigned value even when it fails.
1 parent b27d919 commit ebe5e29

File tree

2 files changed

+21
-1
lines changed

2 files changed

+21
-1
lines changed

ext/uri/php_uri.c

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -325,7 +325,6 @@ static zend_result pass_errors_by_ref_and_free(zval *errors_zv, zval *errors)
325325

326326
ZEND_TRY_ASSIGN_REF_ARR(errors_zv, Z_ARRVAL_P(errors));
327327
if (EG(exception)) {
328-
zval_ptr_dtor(errors);
329328
return FAILURE;
330329
}
331330

ext/uri/tests/057.phpt

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
--TEST--
2+
Test assigning errors by reference fails
3+
--EXTENSIONS--
4+
uri
5+
--FILE--
6+
<?php
7+
8+
class Foo {
9+
public string $x = '';
10+
}
11+
12+
$f = new Foo();
13+
try {
14+
Uri\WhatWg\Url::parse(" https://example.org ", errors: $f->x);
15+
} catch (Throwable $e) {
16+
echo $e::class, ": ", $e->getMessage(), PHP_EOL;
17+
}
18+
19+
?>
20+
--EXPECT--
21+
TypeError: Cannot assign array to reference held by property Foo::$x of type string

0 commit comments

Comments
 (0)