Skip to content

Add some missing null checks #12840

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions Zend/zend_builtin_functions.c
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ ZEND_FUNCTION(func_num_args)

ZEND_PARSE_PARAMETERS_NONE();

if (ZEND_CALL_INFO(ex) & ZEND_CALL_CODE) {
if (ex && (ZEND_CALL_INFO(ex) & ZEND_CALL_CODE)) {
zend_throw_error(NULL, "func_num_args() must be called from a function context");
RETURN_THROWS();
}
Expand Down Expand Up @@ -185,7 +185,7 @@ ZEND_FUNCTION(func_get_arg)
}

ex = EX(prev_execute_data);
if (ZEND_CALL_INFO(ex) & ZEND_CALL_CODE) {
if (ex && (ZEND_CALL_INFO(ex) & ZEND_CALL_CODE)) {
zend_throw_error(NULL, "func_get_arg() cannot be called from the global scope");
RETURN_THROWS();
}
Expand Down Expand Up @@ -223,7 +223,7 @@ ZEND_FUNCTION(func_get_args)

ZEND_PARSE_PARAMETERS_NONE();

if (ZEND_CALL_INFO(ex) & ZEND_CALL_CODE) {
if (ex && (ZEND_CALL_INFO(ex) & ZEND_CALL_CODE)) {
zend_throw_error(NULL, "func_get_args() cannot be called from the global scope");
RETURN_THROWS();
}
Expand Down
6 changes: 4 additions & 2 deletions ext/spl/php_spl.c
Original file line number Diff line number Diff line change
Expand Up @@ -585,8 +585,10 @@ PHP_FUNCTION(spl_autoload_unregister)

if (fcc.function_handler && zend_string_equals_literal(
fcc.function_handler->common.function_name, "spl_autoload_call")) {
/* Don't destroy the hash table, as we might be iterating over it right now. */
zend_hash_clean(spl_autoload_functions);
if (spl_autoload_functions) {
/* Don't destroy the hash table, as we might be iterating over it right now. */
zend_hash_clean(spl_autoload_functions);
}
RETURN_TRUE;
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
--TEST--
spl_autoload_unregister("spl_autoload_call") without registrations
--FILE--
<?php
var_dump(spl_autoload_unregister("spl_autoload_call"));
?>
Done
--EXPECT--
bool(true)
Done
2 changes: 1 addition & 1 deletion ext/standard/basic_functions.c
Original file line number Diff line number Diff line change
Expand Up @@ -1541,7 +1541,7 @@ PHP_FUNCTION(forward_static_call)
Z_PARAM_VARIADIC('*', fci.params, fci.param_count)
ZEND_PARSE_PARAMETERS_END();

if (!EX(prev_execute_data)->func->common.scope) {
if (!EX(prev_execute_data) || !EX(prev_execute_data)->func->common.scope) {
zend_throw_error(NULL, "Cannot call forward_static_call() when no class scope is active");
RETURN_THROWS();
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
--TEST--
register_shutdown_function() without a previous call frame 01
--FILE--
<?php
register_shutdown_function("forward_static_call", "hash_hkdf");
?>
Done
--EXPECT--
Done

Fatal error: Uncaught Error: Cannot call forward_static_call() when no class scope is active in [no active file]:0
Stack trace:
#0 [internal function]: forward_static_call('hash_hkdf')
#1 {main}
thrown in [no active file] on line 0
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
--TEST--
register_shutdown_function() without a previous call frame 02
--FILE--
<?php
register_shutdown_function("func_get_args");
?>
Done
--EXPECT--
Done

Fatal error: Uncaught Error: Cannot call func_get_args() dynamically in [no active file]:0
Stack trace:
#0 [internal function]: func_get_args()
#1 {main}
thrown in [no active file] on line 0
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
--TEST--
register_shutdown_function() without a previous call frame 03
--FILE--
<?php
register_shutdown_function("func_num_args");
?>
Done
--EXPECT--
Done

Fatal error: Uncaught Error: Cannot call func_num_args() dynamically in [no active file]:0
Stack trace:
#0 [internal function]: func_num_args()
#1 {main}
thrown in [no active file] on line 0
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
--TEST--
register_shutdown_function() without a previous call frame 04
--FILE--
<?php
register_shutdown_function("func_get_arg");
?>
Done
--EXPECT--
Done

Fatal error: Uncaught ArgumentCountError: func_get_arg() expects exactly 1 argument, 0 given in [no active file]:0
Stack trace:
#0 [internal function]: func_get_arg()
#1 {main}
thrown in [no active file] on line 0