Skip to content

Commit 0e69329

Browse files
committed
Merge branch 'PHP-8.2' into PHP-8.3
* PHP-8.2: Add missing NULL checks for spl autoload table Add missing NULL pointer checks related to the previous call frame
2 parents 5be5a3d + 9a69bb2 commit 0e69329

9 files changed

+79
-6
lines changed

NEWS

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ PHP NEWS
55
- Core:
66
. Fixed bug GH-12758 / GH-12768 (Invalid opline in OOM handlers within
77
ZEND_FUNC_GET_ARGS and ZEND_BIND_STATIC). (Florian Engelhardt)
8+
. Fix various missing NULL checks. (nielsdos, dstogov)
89

910
- LibXML:
1011
. Fixed test failures for libxml2 2.12.0. (nielsdos)

Zend/zend_builtin_functions.c

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

165165
ZEND_PARSE_PARAMETERS_NONE();
166166

167-
if (ZEND_CALL_INFO(ex) & ZEND_CALL_CODE) {
167+
if (ex && (ZEND_CALL_INFO(ex) & ZEND_CALL_CODE)) {
168168
zend_throw_error(NULL, "func_num_args() must be called from a function context");
169169
RETURN_THROWS();
170170
}
@@ -195,7 +195,7 @@ ZEND_FUNCTION(func_get_arg)
195195
}
196196

197197
ex = EX(prev_execute_data);
198-
if (ZEND_CALL_INFO(ex) & ZEND_CALL_CODE) {
198+
if (ex && (ZEND_CALL_INFO(ex) & ZEND_CALL_CODE)) {
199199
zend_throw_error(NULL, "func_get_arg() cannot be called from the global scope");
200200
RETURN_THROWS();
201201
}
@@ -233,7 +233,7 @@ ZEND_FUNCTION(func_get_args)
233233

234234
ZEND_PARSE_PARAMETERS_NONE();
235235

236-
if (ZEND_CALL_INFO(ex) & ZEND_CALL_CODE) {
236+
if (ex && (ZEND_CALL_INFO(ex) & ZEND_CALL_CODE)) {
237237
zend_throw_error(NULL, "func_get_args() cannot be called from the global scope");
238238
RETURN_THROWS();
239239
}

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
@@ -1533,7 +1533,7 @@ PHP_FUNCTION(forward_static_call)
15331533
Z_PARAM_VARIADIC('*', fci.params, fci.param_count)
15341534
ZEND_PARSE_PARAMETERS_END();
15351535

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