]> granicus.if.org Git - php/commitdiff
Don't use iterator_funcs_ptr if it is null
authorNikita Popov <nikita.ppv@gmail.com>
Thu, 25 Jun 2020 08:30:40 +0000 (10:30 +0200)
committerNikita Popov <nikita.ppv@gmail.com>
Thu, 25 Jun 2020 08:30:40 +0000 (10:30 +0200)
This avoids ubsan warnings. Alternatively we could always initialize
iterator_funcs_ptr for aggregates, instead of doing so only for
non-internal ones.

Zend/zend_interfaces.c
ext/spl/spl_iterators.c

index 6d35e7159c936b7059b7b3917b4e4187856d9cce..3009af2b3f103bc8b82443996350842f60d0d4d4 100644 (file)
@@ -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);
 }
 /* }}} */
 
index 8ddd413cf3d900a86a2de4843ae5893db13064d5..99e130e5d2ff8521205bfb82afa9bb16b4c77765 100644 (file)
@@ -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;