mirror of
https://github.com/php/php-src.git
synced 2024-11-23 09:54:15 +08:00
Fix GH-16808: Segmentation fault in RecursiveIteratorIterator->current() with a xml element input
When the current data is invalid, NULL must be returned. At least that's how the check in SPL works and how other extensions do this as well. If we don't do this, an UNDEF value gets propagated to a return value (misprinted as null); leading to issues. Closes GH-16825.
This commit is contained in:
parent
553d79c709
commit
fbb0061993
4
NEWS
4
NEWS
@ -37,6 +37,10 @@ PHP NEWS
|
||||
. Fixed bug GH-16695 (phar:// tar parser and zero-length file header blocks).
|
||||
(nielsdos, Hans Krentel)
|
||||
|
||||
- SimpleXML:
|
||||
. Fixed bug GH-16808 (Segmentation fault in RecursiveIteratorIterator
|
||||
->current() with a xml element input). (nielsdos)
|
||||
|
||||
21 Nov 2024, PHP 8.2.26
|
||||
|
||||
- Cli:
|
||||
|
@ -2539,7 +2539,11 @@ static zval *php_sxe_iterator_current_data(zend_object_iterator *iter) /* {{{ */
|
||||
{
|
||||
php_sxe_iterator *iterator = (php_sxe_iterator *)iter;
|
||||
|
||||
return &iterator->sxe->iter.data;
|
||||
zval *data = &iterator->sxe->iter.data;
|
||||
if (Z_ISUNDEF_P(data)) {
|
||||
return NULL;
|
||||
}
|
||||
return data;
|
||||
}
|
||||
/* }}} */
|
||||
|
||||
|
12
ext/simplexml/tests/gh16808.phpt
Normal file
12
ext/simplexml/tests/gh16808.phpt
Normal file
@ -0,0 +1,12 @@
|
||||
--TEST--
|
||||
GH-16808 (Segmentation fault in RecursiveIteratorIterator->current() with a xml element input)
|
||||
--EXTENSIONS--
|
||||
simplexml
|
||||
--FILE--
|
||||
<?php
|
||||
$sxe = new SimpleXMLElement("<root />");
|
||||
$test = new RecursiveIteratorIterator($sxe);
|
||||
var_dump($test->current());
|
||||
?>
|
||||
--EXPECT--
|
||||
NULL
|
Loading…
Reference in New Issue
Block a user