Skip to content

Commit bedf108

Browse files
committed
Add missing NULL pointer checks related to the previous call frame
1 parent 061058a commit bedf108

6 files changed

+64
-4
lines changed

Zend/zend_builtin_functions.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,7 @@ ZEND_FUNCTION(func_num_args)
154154

155155
ZEND_PARSE_PARAMETERS_NONE();
156156

157-
if (ZEND_CALL_INFO(ex) & ZEND_CALL_CODE) {
157+
if (ex && (ZEND_CALL_INFO(ex) & ZEND_CALL_CODE)) {
158158
zend_throw_error(NULL, "func_num_args() must be called from a function context");
159159
RETURN_THROWS();
160160
}
@@ -185,7 +185,7 @@ ZEND_FUNCTION(func_get_arg)
185185
}
186186

187187
ex = EX(prev_execute_data);
188-
if (ZEND_CALL_INFO(ex) & ZEND_CALL_CODE) {
188+
if (ex && (ZEND_CALL_INFO(ex) & ZEND_CALL_CODE)) {
189189
zend_throw_error(NULL, "func_get_arg() cannot be called from the global scope");
190190
RETURN_THROWS();
191191
}
@@ -223,7 +223,7 @@ ZEND_FUNCTION(func_get_args)
223223

224224
ZEND_PARSE_PARAMETERS_NONE();
225225

226-
if (ZEND_CALL_INFO(ex) & ZEND_CALL_CODE) {
226+
if (ex && (ZEND_CALL_INFO(ex) & ZEND_CALL_CODE)) {
227227
zend_throw_error(NULL, "func_get_args() cannot be called from the global scope");
228228
RETURN_THROWS();
229229
}

ext/standard/basic_functions.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1541,7 +1541,7 @@ PHP_FUNCTION(forward_static_call)
15411541
Z_PARAM_VARIADIC('*', fci.params, fci.param_count)
15421542
ZEND_PARSE_PARAMETERS_END();
15431543

1544-
if (!EX(prev_execute_data)->func->common.scope) {
1544+
if (!EX(prev_execute_data) || !EX(prev_execute_data)->func->common.scope) {
15451545
zend_throw_error(NULL, "Cannot call forward_static_call() when no class scope is active");
15461546
RETURN_THROWS();
15471547
}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
--TEST--
2+
register_shutdown_function() without a previous call frame 01
3+
--FILE--
4+
<?php
5+
register_shutdown_function("forward_static_call", "hash_hkdf");
6+
?>
7+
Done
8+
--EXPECT--
9+
Done
10+
11+
Fatal error: Uncaught Error: Cannot call forward_static_call() when no class scope is active in [no active file]:0
12+
Stack trace:
13+
#0 [internal function]: forward_static_call('hash_hkdf')
14+
#1 {main}
15+
thrown in [no active file] on line 0
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
--TEST--
2+
register_shutdown_function() without a previous call frame 02
3+
--FILE--
4+
<?php
5+
register_shutdown_function("func_get_args");
6+
?>
7+
Done
8+
--EXPECT--
9+
Done
10+
11+
Fatal error: Uncaught Error: Cannot call func_get_args() dynamically in [no active file]:0
12+
Stack trace:
13+
#0 [internal function]: func_get_args()
14+
#1 {main}
15+
thrown in [no active file] on line 0
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
--TEST--
2+
register_shutdown_function() without a previous call frame 03
3+
--FILE--
4+
<?php
5+
register_shutdown_function("func_num_args");
6+
?>
7+
Done
8+
--EXPECT--
9+
Done
10+
11+
Fatal error: Uncaught Error: Cannot call func_num_args() dynamically in [no active file]:0
12+
Stack trace:
13+
#0 [internal function]: func_num_args()
14+
#1 {main}
15+
thrown in [no active file] on line 0
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
--TEST--
2+
register_shutdown_function() without a previous call frame 04
3+
--FILE--
4+
<?php
5+
register_shutdown_function("func_get_arg");
6+
?>
7+
Done
8+
--EXPECT--
9+
Done
10+
11+
Fatal error: Uncaught ArgumentCountError: func_get_arg() expects exactly 1 argument, 0 given in [no active file]:0
12+
Stack trace:
13+
#0 [internal function]: func_get_arg()
14+
#1 {main}
15+
thrown in [no active file] on line 0

0 commit comments

Comments
 (0)