Skip to content

Commit 0ceaea9

Browse files
authored
Fix GH-25007: PFA named args in constant expression write out of bounds (#25012)
1 parent a8a3635 commit 0ceaea9

3 files changed

Lines changed: 42 additions & 9 deletions

File tree

‎NEWS‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ PHP NEWS
99
(Marti2203).
1010
. Fixed bug GH-25023 (ZEND_CONTAINER_OF() fails to compile with -std=c11).
1111
(lazerg)
12+
. Fixed bug GH-25007 (Partial function application: named args in a constant
13+
expression cause out-of-bounds write in zp_compile()). (lazerg)
1214

1315
- CLI:
1416
. Fixed bug GH-24697 (PHP_HTTP_PARSER_STRICT build option doesn't work).
@@ -97,9 +99,9 @@ PHP NEWS
9799
(ndossche, khaledalam)
98100

99101
- OpenSSL:
102+
. Fixed build with OpenSSL 4.1. (Weilin Du)
100103
. Fixed bug GH-24784 (openssl_pkcs7_read() and openssl_cms_read() overwrite
101104
certificates with CRLs). (Alexander Danilov)
102-
. Fixed build with OpenSSL 4.1. (Weilin Du)
103105

104106
- PDO_PGSQL:
105107
. Fixed bug GH-24461 (DISCARD ALL on persistent connection cleanup drops
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
--TEST--
2+
GH-25007 (PFA in constexpr: named args before a named placeholder)
3+
--FILE--
4+
<?php
5+
6+
function f($a, $b = 2, $c = 3) {
7+
var_dump(func_get_args());
8+
}
9+
10+
const C1 = f(a: 1, b: ?);
11+
const C2 = f(a: 1, c: ?, b: ?);
12+
13+
(C1)(4);
14+
(C2)(5, 6);
15+
16+
?>
17+
--EXPECT--
18+
array(2) {
19+
[0]=>
20+
int(1)
21+
[1]=>
22+
int(4)
23+
}
24+
array(3) {
25+
[0]=>
26+
int(1)
27+
[1]=>
28+
int(6)
29+
[2]=>
30+
int(5)
31+
}

‎Zend/zend_ast.c‎

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -701,14 +701,6 @@ static zend_execute_data *zend_ast_evaluate_arg_list(
701701
if (!arg) {
702702
goto fail;
703703
}
704-
if (named_positions_ptr) {
705-
if (!*named_positions_ptr) {
706-
*named_positions_ptr = zend_new_array(0);
707-
}
708-
zval tmp;
709-
ZVAL_LONG(&tmp, zend_hash_num_elements(*named_positions_ptr));
710-
zend_hash_add(*named_positions_ptr, arg_name, &tmp);
711-
}
712704
arg_ast = arg_ast->child[1];
713705
} else {
714706
arg = ZEND_CALL_VAR_NUM(frame, ZEND_CALL_NUM_ARGS(frame));
@@ -724,6 +716,14 @@ static zend_execute_data *zend_ast_evaluate_arg_list(
724716
} else {
725717
Z_TYPE_INFO_P(arg) = _IS_PLACEHOLDER;
726718
}
719+
if (arg_name && named_positions_ptr) {
720+
if (!*named_positions_ptr) {
721+
*named_positions_ptr = zend_new_array(0);
722+
}
723+
zval tmp;
724+
ZVAL_LONG(&tmp, zend_hash_num_elements(*named_positions_ptr));
725+
zend_hash_add(*named_positions_ptr, arg_name, &tmp);
726+
}
727727
} else {
728728
if (zend_ast_evaluate_ex(arg, arg_ast, scope, short_circuited_ptr, ctx) == FAILURE) {
729729
ZVAL_UNDEF(arg);

0 commit comments

Comments
 (0)