]> granicus.if.org Git - php/commitdiff
- Fix #42703
authorMarcus Boerger <helly@php.net>
Thu, 18 Oct 2007 04:41:39 +0000 (04:41 +0000)
committerMarcus Boerger <helly@php.net>
Thu, 18 Oct 2007 04:41:39 +0000 (04:41 +0000)
ext/spl/spl_iterators.c
ext/spl/tests/bug42703.phpt [new file with mode: 0755]

index a1bb2f008cce27a6c34c2bdc3a6d5aa8a1507cd7..58bf8144f6614aab965a526ec45843d92c3527b2 100755 (executable)
@@ -1124,15 +1124,17 @@ static inline int spl_dual_it_fetch(spl_dual_it_object *intern, int check_more T
        spl_dual_it_free(intern TSRMLS_CC);
        if (!check_more || spl_dual_it_valid(intern TSRMLS_CC) == SUCCESS) {
                intern->inner.iterator->funcs->get_current_data(intern->inner.iterator, &data TSRMLS_CC);
-               intern->current.data = *data;
-               Z_ADDREF_P(intern->current.data);
+               if (data && *data) {
+                       intern->current.data = *data;
+               Z_ADDREF_P(intern->current.data);
+               }
                if (intern->inner.iterator->funcs->get_current_key) {
                        intern->current.key_type = intern->inner.iterator->funcs->get_current_key(intern->inner.iterator, &intern->current.str_key, &intern->current.str_key_len, &intern->current.int_key TSRMLS_CC);
                } else {
                        intern->current.key_type = HASH_KEY_IS_LONG;
                        intern->current.int_key = intern->current.pos;
                }
-               return SUCCESS;
+               return EG(exception) ? FAILURE : SUCCESS;
        }
        return FAILURE;
 }
diff --git a/ext/spl/tests/bug42703.phpt b/ext/spl/tests/bug42703.phpt
new file mode 100755 (executable)
index 0000000..5c52763
--- /dev/null
@@ -0,0 +1,41 @@
+--TEST--
+Bug #42703 (Exception raised in an iterator::current() causes segfault in FilterIterator)
+--FILE--
+<?php
+class BlaIterator implements Iterator
+{
+       public function rewind() { }
+       
+       public function next() { }
+       
+       public function valid() {
+               return true;
+       }
+       
+       public function current()
+       {
+         throw new Exception('boo');
+       }
+       
+       public function key() { }
+}
+
+$it = new BlaIterator();
+$itit = new IteratorIterator($it);
+
+try {
+  foreach($itit as $key => $value) {
+       echo $key, $value;
+  }
+}
+catch (Exception $e) {
+       var_dump($e->getMessage());
+}
+
+var_dump($itit->current());
+var_dump($itit->key());
+?>
+--EXPECTF--
+string(3) "boo"
+NULL
+NULL