From: Nikita Popov Date: Fri, 17 Jul 2020 14:42:21 +0000 (+0200) Subject: Only set DIT type on successful initialization X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=9d2af910336feb8dd91648033fe49fad369564cb;p=php Only set DIT type on successful initialization --- diff --git a/ext/spl/spl_iterators.c b/ext/spl/spl_iterators.c index 047a72082d..cee2b7b39f 100644 --- a/ext/spl/spl_iterators.c +++ b/ext/spl/spl_iterators.c @@ -1290,7 +1290,6 @@ static spl_dual_it_object* spl_dual_it_construct(INTERNAL_FUNCTION_PARAMETERS, z return NULL; } - intern->dit_type = dit_type; switch (dit_type) { case DIT_LimitIterator: { intern->u.limit.offset = 0; /* start at beginning */ @@ -1364,6 +1363,7 @@ static spl_dual_it_object* spl_dual_it_construct(INTERNAL_FUNCTION_PARAMETERS, z if (zend_parse_parameters_none() == FAILURE) { return NULL; } + intern->dit_type = DIT_AppendIterator; zend_replace_error_handling(EH_THROW, spl_ce_InvalidArgumentException, &error_handling); spl_instantiate(spl_ce_ArrayIterator, &intern->u.append.zarrayit); zend_call_method_with_0_params(Z_OBJ(intern->u.append.zarrayit), spl_ce_ArrayIterator, &spl_ce_ArrayIterator->constructor, "__construct", NULL); @@ -1385,8 +1385,6 @@ static spl_dual_it_object* spl_dual_it_construct(INTERNAL_FUNCTION_PARAMETERS, z zend_throw_exception_ex(spl_ce_InvalidArgumentException, 0, "Illegal mode " ZEND_LONG_FMT, mode); return NULL; } - intern->u.regex.mode = mode; - intern->u.regex.regex = zend_string_copy(regex); zend_replace_error_handling(EH_THROW, spl_ce_InvalidArgumentException, &error_handling); intern->u.regex.pce = pcre_get_compiled_regex_cache(regex); @@ -1396,6 +1394,8 @@ static spl_dual_it_object* spl_dual_it_construct(INTERNAL_FUNCTION_PARAMETERS, z /* pcre_get_compiled_regex_cache has already sent error */ return NULL; } + intern->u.regex.mode = mode; + intern->u.regex.regex = zend_string_copy(regex); php_pcre_pce_incref(intern->u.regex.pce); break; } @@ -1420,6 +1420,7 @@ static spl_dual_it_object* spl_dual_it_construct(INTERNAL_FUNCTION_PARAMETERS, z break; } + intern->dit_type = dit_type; if (inc_refcount) { Z_ADDREF_P(zobject); } diff --git a/ext/spl/tests/AppendIterator_invalid_ctor.phpt b/ext/spl/tests/AppendIterator_invalid_ctor.phpt new file mode 100644 index 0000000000..ae22270615 --- /dev/null +++ b/ext/spl/tests/AppendIterator_invalid_ctor.phpt @@ -0,0 +1,14 @@ +--TEST-- +AppendIterator::__construct() with invalid arguments +--FILE-- + +--EXPECTF-- +Fatal error: Uncaught ArgumentCountError: AppendIterator::__construct() expects exactly 0 parameters, 1 given in %s:%d +Stack trace: +#0 %s(%d): AppendIterator->__construct(NULL) +#1 {main} + thrown in %s on line %d