mirror of
https://github.com/php/php-src.git
synced 2025-08-15 21:48:51 +02:00
Fix leak when iterating uninitialized RecursiveIteratorIterator
This commit is contained in:
parent
9ad8fadcbb
commit
3adbafeef7
2 changed files with 19 additions and 5 deletions
|
@ -441,20 +441,18 @@ static const zend_object_iterator_funcs spl_recursive_it_iterator_funcs = {
|
|||
|
||||
static zend_object_iterator *spl_recursive_it_get_iterator(zend_class_entry *ce, zval *zobject, int by_ref)
|
||||
{
|
||||
spl_recursive_it_iterator *iterator;
|
||||
spl_recursive_it_object *object;
|
||||
|
||||
if (by_ref) {
|
||||
zend_throw_error(NULL, "An iterator cannot be used with foreach by reference");
|
||||
return NULL;
|
||||
}
|
||||
iterator = emalloc(sizeof(spl_recursive_it_iterator));
|
||||
object = Z_SPLRECURSIVE_IT_P(zobject);
|
||||
|
||||
spl_recursive_it_object *object = Z_SPLRECURSIVE_IT_P(zobject);
|
||||
if (object->iterators == NULL) {
|
||||
zend_throw_error(NULL, "Object is not initialized");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
spl_recursive_it_iterator *iterator = emalloc(sizeof(spl_recursive_it_iterator));
|
||||
zend_iterator_init((zend_object_iterator*)iterator);
|
||||
|
||||
ZVAL_OBJ_COPY(&iterator->intern.data, Z_OBJ_P(zobject));
|
||||
|
|
16
ext/spl/tests/RecursiveIteratorIterator_not_initialized.phpt
Normal file
16
ext/spl/tests/RecursiveIteratorIterator_not_initialized.phpt
Normal file
|
@ -0,0 +1,16 @@
|
|||
--TEST--
|
||||
Iterating an uninitialized RecursiveIteratorIterator
|
||||
--FILE--
|
||||
<?php
|
||||
|
||||
$rc = new ReflectionClass(RecursiveIteratorIterator::class);
|
||||
$it = $rc->newInstanceWithoutConstructor();
|
||||
try {
|
||||
foreach ($it as $v) {}
|
||||
} catch (Error $e) {
|
||||
echo $e->getMessage(), "\n";
|
||||
}
|
||||
|
||||
?>
|
||||
--EXPECT--
|
||||
Object is not initialized
|
Loading…
Add table
Add a link
Reference in a new issue