Skip to content

Commit

Permalink
Handle ref return from Iterator::key()
Browse files Browse the repository at this point in the history
Handle this in the implementation of get_current_key of user_it,
so that the callers may assume that the key is not a reference.

Fixes oss-fuzz #33018.
  • Loading branch information
nikic committed Apr 15, 2021
1 parent f40c8fd commit 46f9fed
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 0 deletions.
15 changes: 15 additions & 0 deletions Zend/tests/iterator_key_by_ref.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
--TEST--
Iterator::key() with by-ref return
--FILE--
<?php
class Test extends ArrayIterator {
function &key() {
return $foo;
}
}
foreach (new Test([0]) as $k => $v) {
var_dump($k);
}
?>
--EXPECT--
NULL
3 changes: 3 additions & 0 deletions Zend/zend_interfaces.c
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,9 @@ ZEND_API void zend_user_it_get_current_key(zend_object_iterator *_iter, zval *ke
zend_user_iterator *iter = (zend_user_iterator*)_iter;
zval *object = &iter->it.data;
zend_call_method_with_0_params(Z_OBJ_P(object), iter->ce, &iter->ce->iterator_funcs_ptr->zf_key, "key", key);
if (UNEXPECTED(Z_ISREF_P(key))) {
zend_unwrap_reference(key);
}
}
/* }}} */

Expand Down

0 comments on commit 46f9fed

Please sign in to comment.