Skip to content

Commit 395e87d

Browse files
committed
Merge branch 'PHP-7.4'
2 parents 5af8361 + b6f76ac commit 395e87d

4 files changed

+96
-23
lines changed

Zend/tests/call_to_abstract_method_args.phpt

+8
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,14 @@ try {
1313
echo $e->getMessage(), "\n";
1414
}
1515

16+
$ret = new stdClass;
17+
try {
18+
$ret = Test::method(new stdClass);
19+
} catch (Error $e) {
20+
echo $e->getMessage(), "\n";
21+
}
22+
1623
?>
1724
--EXPECT--
1825
Cannot call abstract method Test::method()
26+
Cannot call abstract method Test::method()
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
--TEST--
2+
Check that arguments are freed when calling a deprecated function
3+
--FILE--
4+
<?php
5+
6+
set_error_handler(function($code, $msg) {
7+
throw new Error($msg);
8+
});
9+
10+
try {
11+
ezmlm_hash(new stdClass);
12+
} catch (Error $e) {
13+
echo $e->getMessage(), "\n";
14+
}
15+
16+
$ret = new stdClass;
17+
try {
18+
$ret = ezmlm_hash(new stdClass);
19+
} catch (Error $e) {
20+
echo $e->getMessage(), "\n";
21+
}
22+
23+
try {
24+
$fn = 'ezmlm_hash';
25+
$fn(new stdClass);
26+
} catch (Error $e) {
27+
echo $e->getMessage(), "\n";
28+
}
29+
30+
$ret = new stdClass;
31+
try {
32+
$fn = 'ezmlm_hash';
33+
$ret = $fn(new stdClass);
34+
} catch (Error $e) {
35+
echo $e->getMessage(), "\n";
36+
}
37+
38+
?>
39+
--EXPECT--
40+
Function ezmlm_hash() is deprecated
41+
Function ezmlm_hash() is deprecated
42+
Function ezmlm_hash() is deprecated
43+
Function ezmlm_hash() is deprecated

Zend/zend_vm_def.h

+15-8
Original file line numberDiff line numberDiff line change
@@ -4093,8 +4093,12 @@ ZEND_VM_HOT_HANDLER(131, ZEND_DO_FCALL_BY_NAME, ANY, ANY, SPEC(RETVAL))
40934093
if (UNEXPECTED((fbc->common.fn_flags & ZEND_ACC_DEPRECATED) != 0)) {
40944094
zend_deprecated_function(fbc);
40954095
if (UNEXPECTED(EG(exception) != NULL)) {
4096-
UNDEF_RESULT();
4097-
HANDLE_EXCEPTION();
4096+
UNDEF_RESULT();
4097+
if (!RETURN_VALUE_USED(opline)) {
4098+
ret = &retval;
4099+
ZVAL_UNDEF(ret);
4100+
}
4101+
ZEND_VM_C_GOTO(fcall_end);
40984102
}
40994103
}
41004104

@@ -4126,6 +4130,8 @@ ZEND_VM_HOT_HANDLER(131, ZEND_DO_FCALL_BY_NAME, ANY, ANY, SPEC(RETVAL))
41264130
#endif
41274131

41284132
EG(current_execute_data) = execute_data;
4133+
4134+
ZEND_VM_C_LABEL(fcall_end):
41294135
zend_vm_stack_free_args(call);
41304136
zend_vm_stack_free_call_frame(call);
41314137

@@ -4148,6 +4154,7 @@ ZEND_VM_HOT_HANDLER(60, ZEND_DO_FCALL, ANY, ANY, SPEC(RETVAL))
41484154
zend_execute_data *call = EX(call);
41494155
zend_function *fbc = call->func;
41504156
zval *ret;
4157+
zval retval;
41514158

41524159
SAVE_OPLINE();
41534160
EX(call) = call->prev_execute_data;
@@ -4156,7 +4163,10 @@ ZEND_VM_HOT_HANDLER(60, ZEND_DO_FCALL, ANY, ANY, SPEC(RETVAL))
41564163
zend_abstract_method(fbc);
41574164
ZEND_VM_C_LABEL(fcall_except):
41584165
UNDEF_RESULT();
4159-
zend_vm_stack_free_args(call);
4166+
if (!RETURN_VALUE_USED(opline)) {
4167+
ret = &retval;
4168+
ZVAL_UNDEF(ret);
4169+
}
41604170
ZEND_VM_C_GOTO(fcall_end);
41614171
} else {
41624172
zend_deprecated_function(fbc);
@@ -4187,8 +4197,6 @@ ZEND_VM_C_LABEL(fcall_except):
41874197
zend_execute_ex(call);
41884198
}
41894199
} else {
4190-
zval retval;
4191-
41924200
ZEND_ASSERT(fbc->type == ZEND_INTERNAL_FUNCTION);
41934201
call->prev_execute_data = execute_data;
41944202
EG(current_execute_data) = call;
@@ -4223,14 +4231,14 @@ ZEND_VM_C_LABEL(fcall_except):
42234231
#endif
42244232

42254233
EG(current_execute_data) = execute_data;
4226-
zend_vm_stack_free_args(call);
42274234

4235+
ZEND_VM_C_LABEL(fcall_end):
4236+
zend_vm_stack_free_args(call);
42284237
if (!RETURN_VALUE_USED(opline)) {
42294238
i_zval_ptr_dtor(ret);
42304239
}
42314240
}
42324241

4233-
ZEND_VM_C_LABEL(fcall_end):
42344242
if (UNEXPECTED(ZEND_CALL_INFO(call) & ZEND_CALL_RELEASE_THIS)) {
42354243
OBJ_RELEASE(Z_OBJ(call->This));
42364244
}
@@ -8294,7 +8302,6 @@ ZEND_VM_HANDLER(158, ZEND_CALL_TRAMPOLINE, ANY, ANY)
82948302
EG(current_execute_data) = call->prev_execute_data;
82958303

82968304
zend_vm_stack_free_args(call);
8297-
82988305
if (ret == &retval) {
82998306
zval_ptr_dtor(ret);
83008307
}

Zend/zend_vm_execute.h

+30-15
Original file line numberDiff line numberDiff line change
@@ -1427,8 +1427,12 @@ static ZEND_VM_HOT ZEND_OPCODE_HANDLER_RET ZEND_FASTCALL ZEND_DO_FCALL_BY_NAME_S
14271427
if (UNEXPECTED((fbc->common.fn_flags & ZEND_ACC_DEPRECATED) != 0)) {
14281428
zend_deprecated_function(fbc);
14291429
if (UNEXPECTED(EG(exception) != NULL)) {
1430-
UNDEF_RESULT();
1431-
HANDLE_EXCEPTION();
1430+
UNDEF_RESULT();
1431+
if (!0) {
1432+
ret = &retval;
1433+
ZVAL_UNDEF(ret);
1434+
}
1435+
goto fcall_end;
14321436
}
14331437
}
14341438

@@ -1460,6 +1464,8 @@ static ZEND_VM_HOT ZEND_OPCODE_HANDLER_RET ZEND_FASTCALL ZEND_DO_FCALL_BY_NAME_S
14601464
#endif
14611465

14621466
EG(current_execute_data) = execute_data;
1467+
1468+
fcall_end:
14631469
zend_vm_stack_free_args(call);
14641470
zend_vm_stack_free_call_frame(call);
14651471

@@ -1505,8 +1511,12 @@ static ZEND_VM_HOT ZEND_OPCODE_HANDLER_RET ZEND_FASTCALL ZEND_DO_FCALL_BY_NAME_S
15051511
if (UNEXPECTED((fbc->common.fn_flags & ZEND_ACC_DEPRECATED) != 0)) {
15061512
zend_deprecated_function(fbc);
15071513
if (UNEXPECTED(EG(exception) != NULL)) {
1508-
UNDEF_RESULT();
1509-
HANDLE_EXCEPTION();
1514+
UNDEF_RESULT();
1515+
if (!1) {
1516+
ret = &retval;
1517+
ZVAL_UNDEF(ret);
1518+
}
1519+
goto fcall_end;
15101520
}
15111521
}
15121522

@@ -1538,6 +1548,8 @@ static ZEND_VM_HOT ZEND_OPCODE_HANDLER_RET ZEND_FASTCALL ZEND_DO_FCALL_BY_NAME_S
15381548
#endif
15391549

15401550
EG(current_execute_data) = execute_data;
1551+
1552+
fcall_end:
15411553
zend_vm_stack_free_args(call);
15421554
zend_vm_stack_free_call_frame(call);
15431555

@@ -1560,6 +1572,7 @@ static ZEND_VM_HOT ZEND_OPCODE_HANDLER_RET ZEND_FASTCALL ZEND_DO_FCALL_SPEC_RETV
15601572
zend_execute_data *call = EX(call);
15611573
zend_function *fbc = call->func;
15621574
zval *ret;
1575+
zval retval;
15631576

15641577
SAVE_OPLINE();
15651578
EX(call) = call->prev_execute_data;
@@ -1568,7 +1581,10 @@ static ZEND_VM_HOT ZEND_OPCODE_HANDLER_RET ZEND_FASTCALL ZEND_DO_FCALL_SPEC_RETV
15681581
zend_abstract_method(fbc);
15691582
fcall_except:
15701583
UNDEF_RESULT();
1571-
zend_vm_stack_free_args(call);
1584+
if (!0) {
1585+
ret = &retval;
1586+
ZVAL_UNDEF(ret);
1587+
}
15721588
goto fcall_end;
15731589
} else {
15741590
zend_deprecated_function(fbc);
@@ -1599,8 +1615,6 @@ static ZEND_VM_HOT ZEND_OPCODE_HANDLER_RET ZEND_FASTCALL ZEND_DO_FCALL_SPEC_RETV
15991615
zend_execute_ex(call);
16001616
}
16011617
} else {
1602-
zval retval;
1603-
16041618
ZEND_ASSERT(fbc->type == ZEND_INTERNAL_FUNCTION);
16051619
call->prev_execute_data = execute_data;
16061620
EG(current_execute_data) = call;
@@ -1635,14 +1649,14 @@ static ZEND_VM_HOT ZEND_OPCODE_HANDLER_RET ZEND_FASTCALL ZEND_DO_FCALL_SPEC_RETV
16351649
#endif
16361650

16371651
EG(current_execute_data) = execute_data;
1638-
zend_vm_stack_free_args(call);
16391652

1653+
fcall_end:
1654+
zend_vm_stack_free_args(call);
16401655
if (!0) {
16411656
i_zval_ptr_dtor(ret);
16421657
}
16431658
}
16441659

1645-
fcall_end:
16461660
if (UNEXPECTED(ZEND_CALL_INFO(call) & ZEND_CALL_RELEASE_THIS)) {
16471661
OBJ_RELEASE(Z_OBJ(call->This));
16481662
}
@@ -1663,6 +1677,7 @@ static ZEND_VM_HOT ZEND_OPCODE_HANDLER_RET ZEND_FASTCALL ZEND_DO_FCALL_SPEC_RETV
16631677
zend_execute_data *call = EX(call);
16641678
zend_function *fbc = call->func;
16651679
zval *ret;
1680+
zval retval;
16661681

16671682
SAVE_OPLINE();
16681683
EX(call) = call->prev_execute_data;
@@ -1671,7 +1686,10 @@ static ZEND_VM_HOT ZEND_OPCODE_HANDLER_RET ZEND_FASTCALL ZEND_DO_FCALL_SPEC_RETV
16711686
zend_abstract_method(fbc);
16721687
fcall_except:
16731688
UNDEF_RESULT();
1674-
zend_vm_stack_free_args(call);
1689+
if (!1) {
1690+
ret = &retval;
1691+
ZVAL_UNDEF(ret);
1692+
}
16751693
goto fcall_end;
16761694
} else {
16771695
zend_deprecated_function(fbc);
@@ -1702,8 +1720,6 @@ static ZEND_VM_HOT ZEND_OPCODE_HANDLER_RET ZEND_FASTCALL ZEND_DO_FCALL_SPEC_RETV
17021720
zend_execute_ex(call);
17031721
}
17041722
} else {
1705-
zval retval;
1706-
17071723
ZEND_ASSERT(fbc->type == ZEND_INTERNAL_FUNCTION);
17081724
call->prev_execute_data = execute_data;
17091725
EG(current_execute_data) = call;
@@ -1738,14 +1754,14 @@ static ZEND_VM_HOT ZEND_OPCODE_HANDLER_RET ZEND_FASTCALL ZEND_DO_FCALL_SPEC_RETV
17381754
#endif
17391755

17401756
EG(current_execute_data) = execute_data;
1741-
zend_vm_stack_free_args(call);
17421757

1758+
fcall_end:
1759+
zend_vm_stack_free_args(call);
17431760
if (!1) {
17441761
i_zval_ptr_dtor(ret);
17451762
}
17461763
}
17471764

1748-
fcall_end:
17491765
if (UNEXPECTED(ZEND_CALL_INFO(call) & ZEND_CALL_RELEASE_THIS)) {
17501766
OBJ_RELEASE(Z_OBJ(call->This));
17511767
}
@@ -2806,7 +2822,6 @@ static ZEND_OPCODE_HANDLER_RET ZEND_FASTCALL ZEND_CALL_TRAMPOLINE_SPEC_HANDLER(Z
28062822
EG(current_execute_data) = call->prev_execute_data;
28072823

28082824
zend_vm_stack_free_args(call);
2809-
28102825
if (ret == &retval) {
28112826
zval_ptr_dtor(ret);
28122827
}

0 commit comments

Comments
 (0)