Skip to content

Commit dd29b66

Browse files
committedApr 1, 2023
Fix phpGH-10983: State-dependant segfault in ReflectionObject::getProperties
This is a variant of phpGH-10200, but in a different place. Basically, simplexml may create a properties table that's packed instead of associative. But the macro that was used to loop over the properties table assumed that it was always associative. Replace it by the macro that figures it out automatically which one of the two it is. For test: Co-authored-by: jnvsor Closes phpGH-10984.
1 parent 0d12b3d commit dd29b66

File tree

3 files changed

+28
-1
lines changed

3 files changed

+28
-1
lines changed
 

‎NEWS

+4
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,10 @@ PHP NEWS
1414
- PCRE:
1515
. Fixed bug GH-10968 (Segfault in preg_replace_callback_array()). (ilutov)
1616

17+
- Reflection:
18+
. Fixed bug GH-10983 (State-dependant segfault in
19+
ReflectionObject::getProperties). (nielsdos)
20+
1721
- SPL:
1822
. Handle indirect zvals and use up-to-date properties in
1923
SplFixedArray::__serialize. (nielsdos)

‎ext/reflection/php_reflection.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -4686,7 +4686,7 @@ ZEND_METHOD(ReflectionClass, getProperties)
46864686
if (Z_TYPE(intern->obj) != IS_UNDEF && (filter & ZEND_ACC_PUBLIC) != 0) {
46874687
HashTable *properties = Z_OBJ_HT(intern->obj)->get_properties(Z_OBJ(intern->obj));
46884688
zval *prop;
4689-
ZEND_HASH_MAP_FOREACH_STR_KEY_VAL(properties, key, prop) {
4689+
ZEND_HASH_FOREACH_STR_KEY_VAL(properties, key, prop) {
46904690
_adddynproperty(prop, key, ce, return_value);
46914691
} ZEND_HASH_FOREACH_END();
46924692
}

‎ext/simplexml/tests/gh10983.phpt

+23
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
--TEST--
2+
GH-10983 (State-dependant segfault in ReflectionObject::getProperties)
3+
--EXTENSIONS--
4+
simplexml
5+
--FILE--
6+
<?php
7+
8+
$xml = <<<XML
9+
<form name="test"></form>
10+
XML;
11+
12+
$simplexml = simplexml_load_string($xml);
13+
14+
var_dump($simplexml['name']);
15+
$reflector = new ReflectionObject($simplexml['name']);
16+
$rprops = $reflector->getProperties();
17+
18+
?>
19+
--EXPECT--
20+
object(SimpleXMLElement)#2 (1) {
21+
[0]=>
22+
string(4) "test"
23+
}

0 commit comments

Comments
 (0)
Please sign in to comment.