Skip to content

Commit f37138d

Browse files
committed
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.
1 parent 47fae84 commit f37138d

File tree

2 files changed

+11
-4
lines changed

2 files changed

+11
-4
lines changed

Zend/zend_interfaces.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,8 @@ ZEND_API zval* zend_call_method(zend_object *object, zend_class_entry *obj_ce, z
8989
/* {{{ zend_user_it_new_iterator */
9090
ZEND_API void zend_user_it_new_iterator(zend_class_entry *ce, zval *object, zval *retval)
9191
{
92-
zend_call_method_with_0_params(Z_OBJ_P(object), ce, &ce->iterator_funcs_ptr->zf_new_iterator, "getiterator", retval);
92+
zend_call_known_instance_method_with_0_params(
93+
ce->iterator_funcs_ptr->zf_new_iterator, Z_OBJ_P(object), retval);
9394
}
9495
/* }}} */
9596

ext/spl/spl_iterators.c

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -487,7 +487,9 @@ static void spl_recursive_it_it_construct(INTERNAL_FUNCTION_PARAMETERS, zend_cla
487487

488488
zend_replace_error_handling(EH_THROW, spl_ce_InvalidArgumentException, &error_handling);
489489
if (instanceof_function(Z_OBJCE_P(iterator), zend_ce_aggregate)) {
490-
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);
490+
zend_function **getiterator_cache = Z_OBJCE_P(iterator)->iterator_funcs_ptr
491+
? &Z_OBJCE_P(iterator)->iterator_funcs_ptr->zf_new_iterator : NULL;
492+
zend_call_method_with_0_params(Z_OBJ_P(iterator), Z_OBJCE_P(iterator), getiterator_cache, "getiterator", &aggregate_retval);
491493
iterator = &aggregate_retval;
492494
} else {
493495
Z_ADDREF_P(iterator);
@@ -510,7 +512,9 @@ static void spl_recursive_it_it_construct(INTERNAL_FUNCTION_PARAMETERS, zend_cla
510512

511513
zend_replace_error_handling(EH_THROW, spl_ce_InvalidArgumentException, &error_handling);
512514
if (instanceof_function(Z_OBJCE_P(iterator), zend_ce_aggregate)) {
513-
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);
515+
zend_function **getiterator_cache = Z_OBJCE_P(iterator)->iterator_funcs_ptr
516+
? &Z_OBJCE_P(iterator)->iterator_funcs_ptr->zf_new_iterator : NULL;
517+
zend_call_method_with_0_params(Z_OBJ_P(iterator), Z_OBJCE_P(iterator), getiterator_cache, "getiterator", &aggregate_retval);
514518
iterator = &aggregate_retval;
515519
} else {
516520
Z_ADDREF_P(iterator);
@@ -1362,7 +1366,9 @@ static spl_dual_it_object* spl_dual_it_construct(INTERNAL_FUNCTION_PARAMETERS, z
13621366
ce = ce_cast;
13631367
}
13641368
if (instanceof_function(ce, zend_ce_aggregate)) {
1365-
zend_call_method_with_0_params(Z_OBJ_P(zobject), ce, &ce->iterator_funcs_ptr->zf_new_iterator, "getiterator", &retval);
1369+
zend_function **getiterator_cache =
1370+
ce->iterator_funcs_ptr ? &ce->iterator_funcs_ptr->zf_new_iterator : NULL;
1371+
zend_call_method_with_0_params(Z_OBJ_P(zobject), ce, getiterator_cache, "getiterator", &retval);
13661372
if (EG(exception)) {
13671373
zval_ptr_dtor(&retval);
13681374
return NULL;

0 commit comments

Comments
 (0)