Skip to content

Commit b5834c1

Browse files
committed
Fix GH-15837: Segmentation fault in ext/simplexml/simplexml.c
We should check if the iterator data is still valid, because if it isn't, then the type info is UNDEF, but the pointer value may be dangling. Closes GH-15841.
1 parent 34dcea8 commit b5834c1

File tree

3 files changed

+39
-0
lines changed

3 files changed

+39
-0
lines changed

NEWS

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,10 @@ PHP NEWS
88
. Fixed regression where signs after the first one were ignored while parsing
99
a signed integer, with the DateTimeInterface::modify() function. (Derick)
1010

11+
- SimpleXML:
12+
. Fixed bug GH-15837 (Segmentation fault in ext/simplexml/simplexml.c).
13+
(nielsdos)
14+
1115
- SOAP:
1216
. Fixed bug #62900 (Wrong namespace on xsd import error message). (nielsdos)
1317

ext/simplexml/simplexml.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2547,6 +2547,11 @@ static void php_sxe_iterator_current_key(zend_object_iterator *iter, zval *key)
25472547
{
25482548
php_sxe_iterator *iterator = (php_sxe_iterator *)iter;
25492549
zval *curobj = &iterator->sxe->iter.data;
2550+
if (Z_ISUNDEF_P(curobj)) {
2551+
ZVAL_NULL(key);
2552+
return;
2553+
}
2554+
25502555
php_sxe_object *intern = Z_SXEOBJ_P(curobj);
25512556

25522557
xmlNodePtr curnode = NULL;

ext/simplexml/tests/gh15837.phpt

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
--TEST--
2+
GH-15837 (Segmentation fault in ext/simplexml/simplexml.c)
3+
--CREDITS--
4+
YuanchengJiang
5+
--FILE--
6+
<?php
7+
$xml =<<<EOF
8+
<xml>
9+
<fieldset1>
10+
</fieldset1>
11+
<fieldset2>
12+
<options>
13+
</options>
14+
</fieldset2>
15+
</xml>
16+
EOF;
17+
$sxe = new SimpleXMLIterator($xml);
18+
$rit = new RecursiveIteratorIterator($sxe, RecursiveIteratorIterator::LEAVES_ONLY);
19+
foreach ($rit as $child) {
20+
$ancestry = $child->xpath('ancestor-or-self::*');
21+
// Exhaust internal iterator
22+
foreach ($ancestry as $ancestor) {
23+
}
24+
}
25+
var_dump($rit->valid());
26+
var_dump($rit->key());
27+
?>
28+
--EXPECT--
29+
bool(false)
30+
NULL

0 commit comments

Comments
 (0)