diff options
author | Nikita Popov <nikita.ppv@gmail.com> | 2020-06-25 10:30:40 +0200 |
---|---|---|
committer | Nikita Popov <nikita.ppv@gmail.com> | 2020-06-25 10:30:40 +0200 |
commit | f37138d2c5408916ed80839b94431d268b7fe24f (patch) | |
tree | f446b5651c9c92820ae6ae953e4f768406a1a902 | |
parent | 47fae8425f5d03060e33b0960084b04a60ee1a21 (diff) | |
download | php-git-f37138d2c5408916ed80839b94431d268b7fe24f.tar.gz |
Don't use iterator_funcs_ptr if it is null
This avoids ubsan warnings. Alternatively we could always initialize
iterator_funcs_ptr for aggregates, instead of doing so only for
non-internal ones.
-rw-r--r-- | Zend/zend_interfaces.c | 3 | ||||
-rw-r--r-- | ext/spl/spl_iterators.c | 12 |
2 files changed, 11 insertions, 4 deletions
diff --git a/Zend/zend_interfaces.c b/Zend/zend_interfaces.c index 6d35e7159c..3009af2b3f 100644 --- a/Zend/zend_interfaces.c +++ b/Zend/zend_interfaces.c @@ -89,7 +89,8 @@ ZEND_API zval* zend_call_method(zend_object *object, zend_class_entry *obj_ce, z /* {{{ zend_user_it_new_iterator */ ZEND_API void zend_user_it_new_iterator(zend_class_entry *ce, zval *object, zval *retval) { - zend_call_method_with_0_params(Z_OBJ_P(object), ce, &ce->iterator_funcs_ptr->zf_new_iterator, "getiterator", retval); + zend_call_known_instance_method_with_0_params( + ce->iterator_funcs_ptr->zf_new_iterator, Z_OBJ_P(object), retval); } /* }}} */ diff --git a/ext/spl/spl_iterators.c b/ext/spl/spl_iterators.c index 8ddd413cf3..99e130e5d2 100644 --- a/ext/spl/spl_iterators.c +++ b/ext/spl/spl_iterators.c @@ -487,7 +487,9 @@ static void spl_recursive_it_it_construct(INTERNAL_FUNCTION_PARAMETERS, zend_cla zend_replace_error_handling(EH_THROW, spl_ce_InvalidArgumentException, &error_handling); if (instanceof_function(Z_OBJCE_P(iterator), zend_ce_aggregate)) { - zend_call_method_with_0_params(Z_OBJ_P(iterator), Z_OBJCE_P(iterator), &Z_OBJCE_P(iterator)->iterator_funcs_ptr->zf_new_iterator, "getiterator", &aggregate_retval); + zend_function **getiterator_cache = Z_OBJCE_P(iterator)->iterator_funcs_ptr + ? &Z_OBJCE_P(iterator)->iterator_funcs_ptr->zf_new_iterator : NULL; + zend_call_method_with_0_params(Z_OBJ_P(iterator), Z_OBJCE_P(iterator), getiterator_cache, "getiterator", &aggregate_retval); iterator = &aggregate_retval; } else { Z_ADDREF_P(iterator); @@ -510,7 +512,9 @@ static void spl_recursive_it_it_construct(INTERNAL_FUNCTION_PARAMETERS, zend_cla zend_replace_error_handling(EH_THROW, spl_ce_InvalidArgumentException, &error_handling); if (instanceof_function(Z_OBJCE_P(iterator), zend_ce_aggregate)) { - zend_call_method_with_0_params(Z_OBJ_P(iterator), Z_OBJCE_P(iterator), &Z_OBJCE_P(iterator)->iterator_funcs_ptr->zf_new_iterator, "getiterator", &aggregate_retval); + zend_function **getiterator_cache = Z_OBJCE_P(iterator)->iterator_funcs_ptr + ? &Z_OBJCE_P(iterator)->iterator_funcs_ptr->zf_new_iterator : NULL; + zend_call_method_with_0_params(Z_OBJ_P(iterator), Z_OBJCE_P(iterator), getiterator_cache, "getiterator", &aggregate_retval); iterator = &aggregate_retval; } else { Z_ADDREF_P(iterator); @@ -1362,7 +1366,9 @@ static spl_dual_it_object* spl_dual_it_construct(INTERNAL_FUNCTION_PARAMETERS, z ce = ce_cast; } if (instanceof_function(ce, zend_ce_aggregate)) { - zend_call_method_with_0_params(Z_OBJ_P(zobject), ce, &ce->iterator_funcs_ptr->zf_new_iterator, "getiterator", &retval); + zend_function **getiterator_cache = + ce->iterator_funcs_ptr ? &ce->iterator_funcs_ptr->zf_new_iterator : NULL; + zend_call_method_with_0_params(Z_OBJ_P(zobject), ce, getiterator_cache, "getiterator", &retval); if (EG(exception)) { zval_ptr_dtor(&retval); return NULL; |