Skip to content

Commit 5e75310

Browse files
nielsdosmvorisek
authored andcommitted
Fix GH-10801: Named arguments in CTE functions cause a segfault
Fixes GH-10801 Named arguments are not supported by the constant evaluation routine, in the sense that they are ignored. This causes two issues: - It causes a crash because not all oplines belonging to the call are removed, which results in SEND_VA{L,R} which should've been removed. - It causes semantic issues (demonstrated in the test case). This case never worked anyway, leading to crashes or incorrect behaviour, so just prevent CTE of calls with named parameters for now. We can choose to support it later, but introducing support for this in a stable branch seems too dangerous. This patch does not change the removal of SEND_* opcodes in remove_call because the crash bug can't be triggered anymore with this patch as there are no named parameters anymore and no variadic CTE functions exist.
1 parent 8525ece commit 5e75310

File tree

2 files changed

+25
-2
lines changed

2 files changed

+25
-2
lines changed

Zend/Optimizer/sccp.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1646,8 +1646,9 @@ static void sccp_visit_instr(scdf_ctx *scdf, zend_op *opline, zend_ssa_op *ssa_o
16461646
break;
16471647
}
16481648

1649-
/* We're only interested in functions with up to three arguments right now */
1650-
if (call->num_args > 3 || call->send_unpack || call->is_prototype) {
1649+
/* We're only interested in functions with up to three arguments right now.
1650+
* Note that named arguments with the argument in declaration order will still work. */
1651+
if (call->num_args > 3 || call->send_unpack || call->is_prototype || call->named_args) {
16511652
SET_RESULT_BOT(result);
16521653
break;
16531654
}

ext/opcache/tests/opt/gh10801.phpt

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
--TEST--
2+
GH-10801 (Named arguments in CTE functions cause a segfault)
3+
--INI--
4+
opcache.enable=1
5+
opcache.enable_cli=1
6+
opcache.optimization_level=0xe0
7+
--EXTENSIONS--
8+
opcache
9+
--FILE--
10+
<?php
11+
// Named argument case and does not do CTE as expected
12+
print_r(array_keys(array: [1 => 1], strict: true, filter_value: 0));
13+
// Will not use named arguments and do CTE as expected
14+
print_r(array_keys(array: [1 => 1], filter_value: 0, strict: true));
15+
?>
16+
--EXPECT--
17+
Array
18+
(
19+
)
20+
Array
21+
(
22+
)

0 commit comments

Comments
 (0)