Skip to content

Commit b30d089

Browse files
committed
Fixes
1 parent d0b408b commit b30d089

File tree

3 files changed

+51
-9
lines changed

3 files changed

+51
-9
lines changed

Zend/tests/named_params/defaults.phpt

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
--TEST--
2+
Skipping over default parameters
3+
--FILE--
4+
<?php
5+
6+
function test1($a = 'a', $b = 'b') {
7+
echo "a: $a, b: $b\n";
8+
}
9+
10+
function test2($a = SOME_CONST, $b = 'b') {
11+
echo "a: $a, b: $b\n";
12+
}
13+
14+
function test3($a = SOME_OTHER_CONST, $b = 'b') {
15+
echo "a: $a, b: $b\n";
16+
}
17+
18+
test1(b: 'B');
19+
20+
define('SOME_CONST', 'X');
21+
test2(b: 'B');
22+
23+
// NB: We also want to test the stack trace.
24+
test3(b: 'B');
25+
26+
?>
27+
--EXPECTF--
28+
a: a, b: B
29+
a: X, b: B
30+
31+
Fatal error: Uncaught Error: Undefined constant "SOME_OTHER_CONST" in %s:%d
32+
Stack trace:
33+
#0 %s(%d): test3(NULL, 'B')
34+
#1 {main}
35+
thrown in %s on line %d

Zend/zend_execute.c

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4470,28 +4470,33 @@ ZEND_API int ZEND_FASTCALL zend_handle_undef_args(zend_execute_data *call) {
44704470
continue;
44714471
}
44724472

4473-
zend_op *opline = &fbc->op_array.opcodes[i];
4473+
zend_op_array *op_array = &fbc->op_array;
4474+
zend_op *opline = &op_array->opcodes[i];
44744475
if (EXPECTED(opline->opcode == ZEND_RECV_INIT)) {
44754476
zval *default_value = RT_CONSTANT(opline, opline->op2);
44764477
if (Z_OPT_TYPE_P(default_value) == IS_CONSTANT_AST) {
4478+
void *run_time_cache = RUN_TIME_CACHE(op_array);
44774479
zval *cache_val =
4478-
(zval *) ((char *) call->run_time_cache + Z_CACHE_SLOT_P(default_value));
4480+
(zval *) ((char *) run_time_cache + Z_CACHE_SLOT_P(default_value));
44794481

4480-
/* We keep in cache only not refcounted values */
44814482
if (Z_TYPE_P(cache_val) != IS_UNDEF) {
4483+
/* We keep in cache only not refcounted values */
44824484
ZVAL_COPY_VALUE(arg, cache_val);
44834485
} else {
4484-
ZVAL_COPY(arg, default_value);
4486+
/* Update constant inside a temporary zval, to make sure the CONSTANT_AST
4487+
* value is not accessible through back traces. */
4488+
zval tmp;
4489+
ZVAL_COPY(&tmp, default_value);
44854490
start_fake_frame(call, opline);
4486-
int ret = zval_update_constant_ex(arg, fbc->op_array.scope);
4491+
int ret = zval_update_constant_ex(&tmp, fbc->op_array.scope);
44874492
end_fake_frame(call);
44884493
if (UNEXPECTED(ret == FAILURE)) {
4489-
zval_ptr_dtor_nogc(arg);
4490-
ZVAL_UNDEF(arg);
4494+
zval_ptr_dtor_nogc(&tmp);
44914495
return FAILURE;
44924496
}
4493-
if (!Z_REFCOUNTED_P(arg)) {
4494-
ZVAL_COPY_VALUE(cache_val, arg);
4497+
ZVAL_COPY_VALUE(arg, &tmp);
4498+
if (!Z_REFCOUNTED(tmp)) {
4499+
ZVAL_COPY_VALUE(cache_val, &tmp);
44954500
}
44964501
}
44974502
} else {

ext/opcache/jit/zend_jit_x86.dasc

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8568,8 +8568,10 @@ static int zend_jit_do_fcall(dasm_State **Dst, const zend_op *opline, const zend
85688568
}
85698569

85708570
// TODO: This could be more precise by checking MAY_BE_ARRAY_KEY_STRING for unpacks.
8571+
// TODO: Clean this up.
85718572
bool may_have_named_args = 0;
85728573
if ((opline-1)->opcode == ZEND_SEND_UNPACK || (opline-1)->opcode == ZEND_SEND_ARRAY ||
8574+
(opline-1)->opcode == ZEND_CHECK_NAMED ||
85738575
opline->extended_value == ZEND_FCALL_HAS_NAMED_ARGS) {
85748576
unknown_num_args = 1;
85758577
may_have_named_args = 1;

0 commit comments

Comments
 (0)