Skip to content

Commit f283f50

Browse files
committed
Merge branch 'PHP-8.3'
* PHP-8.3: Add missing NULL checks for spl autoload table Add missing NULL pointer checks related to the previous call frame
2 parents 4d51d58 + 0e69329 commit f283f50

8 files changed

+78
-6
lines changed

Zend/zend_builtin_functions.c

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

169169
ZEND_PARSE_PARAMETERS_NONE();
170170

171-
if (ZEND_CALL_INFO(ex) & ZEND_CALL_CODE) {
171+
if (ex && (ZEND_CALL_INFO(ex) & ZEND_CALL_CODE)) {
172172
zend_throw_error(NULL, "func_num_args() must be called from a function context");
173173
RETURN_THROWS();
174174
}
@@ -199,7 +199,7 @@ ZEND_FUNCTION(func_get_arg)
199199
}
200200

201201
ex = EX(prev_execute_data);
202-
if (ZEND_CALL_INFO(ex) & ZEND_CALL_CODE) {
202+
if (ex && (ZEND_CALL_INFO(ex) & ZEND_CALL_CODE)) {
203203
zend_throw_error(NULL, "func_get_arg() cannot be called from the global scope");
204204
RETURN_THROWS();
205205
}
@@ -237,7 +237,7 @@ ZEND_FUNCTION(func_get_args)
237237

238238
ZEND_PARSE_PARAMETERS_NONE();
239239

240-
if (ZEND_CALL_INFO(ex) & ZEND_CALL_CODE) {
240+
if (ex && (ZEND_CALL_INFO(ex) & ZEND_CALL_CODE)) {
241241
zend_throw_error(NULL, "func_get_args() cannot be called from the global scope");
242242
RETURN_THROWS();
243243
}

ext/spl/php_spl.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -588,8 +588,10 @@ PHP_FUNCTION(spl_autoload_unregister)
588588

589589
if (fcc.function_handler && zend_string_equals_literal(
590590
fcc.function_handler->common.function_name, "spl_autoload_call")) {
591-
/* Don't destroy the hash table, as we might be iterating over it right now. */
592-
zend_hash_clean(spl_autoload_functions);
591+
if (spl_autoload_functions) {
592+
/* Don't destroy the hash table, as we might be iterating over it right now. */
593+
zend_hash_clean(spl_autoload_functions);
594+
}
593595
RETURN_TRUE;
594596
}
595597

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
--TEST--
2+
spl_autoload_unregister("spl_autoload_call") without registrations
3+
--FILE--
4+
<?php
5+
var_dump(spl_autoload_unregister("spl_autoload_call"));
6+
?>
7+
Done
8+
--EXPECT--
9+
bool(true)
10+
Done

ext/standard/basic_functions.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1525,7 +1525,7 @@ PHP_FUNCTION(forward_static_call)
15251525
Z_PARAM_VARIADIC('*', fci.params, fci.param_count)
15261526
ZEND_PARSE_PARAMETERS_END();
15271527

1528-
if (!EX(prev_execute_data)->func->common.scope) {
1528+
if (!EX(prev_execute_data) || !EX(prev_execute_data)->func->common.scope) {
15291529
zend_throw_error(NULL, "Cannot call forward_static_call() when no class scope is active");
15301530
RETURN_THROWS();
15311531
}
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)