]> granicus.if.org Git - php/commitdiff
- Fixed bug #54281 (Crash in non-initialized RecursiveIteratorIterator)
authorFelipe Pena <felipe@php.net>
Tue, 22 Mar 2011 22:41:16 +0000 (22:41 +0000)
committerFelipe Pena <felipe@php.net>
Tue, 22 Mar 2011 22:41:16 +0000 (22:41 +0000)
ext/spl/spl_iterators.c
ext/spl/tests/bug54281.phpt [new file with mode: 0644]

index cabf9f55f33034bf53a2397e2de039d76c55adb9..1766d2a4268f74de67f36eb644f057dc5ffe7b77 100755 (executable)
@@ -360,6 +360,10 @@ next_step:
 static void spl_recursive_it_rewind_ex(spl_recursive_it_object *object, zval *zthis TSRMLS_DC)
 {
        zend_object_iterator      *sub_iter;
+       
+       if (!object->iterators) {
+               php_error_docref(NULL TSRMLS_CC, E_ERROR, "The %s instance wasn't initialized properly", Z_OBJCE_P(zthis)->name);
+       }
 
        while (object->level) {
                sub_iter = object->iterators[object->level].iterator;
diff --git a/ext/spl/tests/bug54281.phpt b/ext/spl/tests/bug54281.phpt
new file mode 100644 (file)
index 0000000..d42d9e5
--- /dev/null
@@ -0,0 +1,15 @@
+--TEST--
+Bug #54281 (Crash in spl_recursive_it_rewind_ex)
+--FILE--
+<?php
+
+class RecursiveArrayIteratorIterator extends RecursiveIteratorIterator {
+       function __construct($it, $max_depth) { }
+}
+$it = new RecursiveArrayIteratorIterator(new RecursiveArrayIterator(array()), 2);
+
+foreach($it as $k=>$v) { }
+
+?>
+--EXPECTF--
+Fatal error: RecursiveIteratorIterator::rewind(): The RecursiveArrayIteratorIterator instance wasn't initialized properly in %s on line %d