Skip to content

Commit 88af091

Browse files
committed
Merge branch 'PHP-8.2' into PHP-8.3
* PHP-8.2: Fix GH-14290: Member access within null pointer in extension spl
2 parents 4b8ce06 + b3a56bd commit 88af091

File tree

3 files changed

+28
-4
lines changed

3 files changed

+28
-4
lines changed

NEWS

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@ PHP NEWS
22
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
33
?? ??? ????, PHP 8.3.9
44

5+
- SPL:
6+
. Fixed bug GH-14290 (Member access within null pointer in extension spl).
7+
(nielsdos)
58

69
23 May 2024, PHP 8.3.8RC1
710

ext/spl/spl_iterators.c

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1898,12 +1898,17 @@ PHP_METHOD(RegexIterator, accept)
18981898
zval *replacement = zend_read_property(intern->std.ce, Z_OBJ_P(ZEND_THIS), "replacement", sizeof("replacement")-1, 1, &rv);
18991899
zend_string *replacement_str = zval_try_get_string(replacement);
19001900

1901-
if (UNEXPECTED(!replacement_str)) {
1902-
RETURN_THROWS();
1903-
}
1901+
/* Property type is ?string, so this should always succeed. */
1902+
ZEND_ASSERT(replacement_str != NULL);
19041903

19051904
result = php_pcre_replace_impl(intern->u.regex.pce, subject, ZSTR_VAL(subject), ZSTR_LEN(subject), replacement_str, -1, &count);
19061905

1906+
if (UNEXPECTED(!result)) {
1907+
zend_string_release(replacement_str);
1908+
zend_string_release_ex(subject, false);
1909+
RETURN_FALSE;
1910+
}
1911+
19071912
if (intern->u.regex.flags & REGIT_USE_KEY) {
19081913
zval_ptr_dtor(&intern->current.key);
19091914
ZVAL_STR(&intern->current.key, result);
@@ -1920,7 +1925,7 @@ PHP_METHOD(RegexIterator, accept)
19201925
if (intern->u.regex.flags & REGIT_INVERTED) {
19211926
RETVAL_BOOL(Z_TYPE_P(return_value) != IS_TRUE);
19221927
}
1923-
zend_string_release_ex(subject, 0);
1928+
zend_string_release_ex(subject, false);
19241929
} /* }}} */
19251930

19261931
/* {{{ Returns current regular expression */

ext/spl/tests/gh14290.phpt

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
--TEST--
2+
GH-14290 (Member access within null pointer in extension spl)
3+
--INI--
4+
pcre.backtrack_limit=2
5+
pcre.jit=0
6+
--FILE--
7+
<?php
8+
$h = new ArrayIterator(['test' => 'test1']);
9+
$i = new RegexIterator($h, '/^test(.*)/', RegexIterator::REPLACE);
10+
foreach ($i as $name => $value) {
11+
var_dump($name, $value);
12+
}
13+
echo "Done\n";
14+
?>
15+
--EXPECT--
16+
Done

0 commit comments

Comments
 (0)