Skip to content

Commit 9d2af91

Browse files
committed
Only set DIT type on successful initialization
1 parent d625c29 commit 9d2af91

File tree

2 files changed

+18
-3
lines changed

2 files changed

+18
-3
lines changed

ext/spl/spl_iterators.c

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1290,7 +1290,6 @@ static spl_dual_it_object* spl_dual_it_construct(INTERNAL_FUNCTION_PARAMETERS, z
12901290
return NULL;
12911291
}
12921292

1293-
intern->dit_type = dit_type;
12941293
switch (dit_type) {
12951294
case DIT_LimitIterator: {
12961295
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
13641363
if (zend_parse_parameters_none() == FAILURE) {
13651364
return NULL;
13661365
}
1366+
intern->dit_type = DIT_AppendIterator;
13671367
zend_replace_error_handling(EH_THROW, spl_ce_InvalidArgumentException, &error_handling);
13681368
spl_instantiate(spl_ce_ArrayIterator, &intern->u.append.zarrayit);
13691369
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
13851385
zend_throw_exception_ex(spl_ce_InvalidArgumentException, 0, "Illegal mode " ZEND_LONG_FMT, mode);
13861386
return NULL;
13871387
}
1388-
intern->u.regex.mode = mode;
1389-
intern->u.regex.regex = zend_string_copy(regex);
13901388

13911389
zend_replace_error_handling(EH_THROW, spl_ce_InvalidArgumentException, &error_handling);
13921390
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
13961394
/* pcre_get_compiled_regex_cache has already sent error */
13971395
return NULL;
13981396
}
1397+
intern->u.regex.mode = mode;
1398+
intern->u.regex.regex = zend_string_copy(regex);
13991399
php_pcre_pce_incref(intern->u.regex.pce);
14001400
break;
14011401
}
@@ -1420,6 +1420,7 @@ static spl_dual_it_object* spl_dual_it_construct(INTERNAL_FUNCTION_PARAMETERS, z
14201420
break;
14211421
}
14221422

1423+
intern->dit_type = dit_type;
14231424
if (inc_refcount) {
14241425
Z_ADDREF_P(zobject);
14251426
}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
--TEST--
2+
AppendIterator::__construct() with invalid arguments
3+
--FILE--
4+
<?php
5+
6+
new AppendIterator(null);
7+
8+
?>
9+
--EXPECTF--
10+
Fatal error: Uncaught ArgumentCountError: AppendIterator::__construct() expects exactly 0 parameters, 1 given in %s:%d
11+
Stack trace:
12+
#0 %s(%d): AppendIterator->__construct(NULL)
13+
#1 {main}
14+
thrown in %s on line %d

0 commit comments

Comments
 (0)