Skip to content

Commit 5897071

Browse files
authored
Fix refcounting on zend_empty_array in ext-uri (GH-19908)
Fixes GH-19892
1 parent 9fe6fb2 commit 5897071

File tree

4 files changed

+15
-1
lines changed

4 files changed

+15
-1
lines changed

NEWS

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ PHP NEWS
5858
. Add new Uri\UriError exception that is thrown for internal error
5959
conditions. (timwolla)
6060
. Further clean up the internal API. (timwolla)
61+
. Fixed bug GH-19892 (Refcounting on zend_empty_array). (ilutov, timwolla)
6162

6263
- Windows:
6364
. Fix GH-19722 (_get_osfhandle asserts in debug mode when given a socket).

Zend/zend_API.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1364,6 +1364,7 @@ ZEND_API zend_result zend_try_assign_typed_ref_zval_ex(zend_reference *ref, zval
13641364

13651365
#define ZEND_TRY_ASSIGN_REF_ARR(zv, arr) do { \
13661366
ZEND_ASSERT(Z_ISREF_P(zv)); \
1367+
ZEND_ASSERT(!(GC_FLAGS(arr) & GC_IMMUTABLE)); \
13671368
_ZEND_TRY_ASSIGN_ARR(zv, arr, 1); \
13681369
} while (0)
13691370

ext/uri/php_uri.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -308,7 +308,7 @@ static zend_result pass_errors_by_ref_and_free(zval *errors_zv, zval *errors)
308308
return SUCCESS;
309309
}
310310

311-
ZEND_TRY_ASSIGN_REF_ARR(errors_zv, Z_ARRVAL_P(errors));
311+
ZEND_TRY_ASSIGN_REF_TMP(errors_zv, errors);
312312
if (EG(exception)) {
313313
return FAILURE;
314314
}

ext/uri/tests/gh19892.phpt

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
--TEST--
2+
GH-19892: Successful \Uri\WhatWg\Url::parse() with empty errors array
3+
--FILE--
4+
<?php
5+
6+
\Uri\WhatWg\Url::parse('https://example.com', errors: $errors);
7+
var_dump($errors);
8+
9+
?>
10+
--EXPECT--
11+
array(0) {
12+
}

0 commit comments

Comments
 (0)