com php-src: Only set DIT type on successful initialization: ext/spl/spl_iterators.c ext/spl/tests/AppendIterator_in valid_ctor.phpt

From: Date: Fri, 17 Jul 2020 14:42:56 +0000
Subject: com php-src: Only set DIT type on successful initialization: ext/spl/spl_iterators.c ext/spl/tests/AppendIterator_in valid_ctor.phpt
Groups: php.cvs 
Request: Send a blank email to php-cvs+get-112220@lists.php.net to get a copy of this message
Commit: 9d2af910336feb8dd91648033fe49fad369564cb Author: Nikita Popov <nikita.ppv@gmail.com> Fri, 17 Jul 2020 16:42:21 +0200 Parents: d625c29df7b4bdb1abe2aa0bc987aecfd534fd54 Branches: master Link: http://git.php.net/?p=php-src.git;a=commitdiff;h=9d2af910336feb8dd91648033fe49fad369564cb Log: Only set DIT type on successful initialization Changed paths: M ext/spl/spl_iterators.c A ext/spl/tests/AppendIterator_invalid_ctor.phpt Diff: 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-- +<?php + +new AppendIterator(null); + +?> +--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

« previous php.cvs (#112220) next »