diff --git a/Zend/zend_builtin_functions.c b/Zend/zend_builtin_functions.c index 5cebbbc560894..9c4b836caface 100644 --- a/Zend/zend_builtin_functions.c +++ b/Zend/zend_builtin_functions.c @@ -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(); } @@ -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(); } @@ -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(); } diff --git a/ext/spl/php_spl.c b/ext/spl/php_spl.c index 710b2f97ffb9a..715b10c456dea 100644 --- a/ext/spl/php_spl.c +++ b/ext/spl/php_spl.c @@ -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; } diff --git a/ext/spl/tests/spl_autoload_unregister_without_registrations.phpt b/ext/spl/tests/spl_autoload_unregister_without_registrations.phpt new file mode 100644 index 0000000000000..0a7ca5a1352fd --- /dev/null +++ b/ext/spl/tests/spl_autoload_unregister_without_registrations.phpt @@ -0,0 +1,10 @@ +--TEST-- +spl_autoload_unregister("spl_autoload_call") without registrations +--FILE-- + +Done +--EXPECT-- +bool(true) +Done diff --git a/ext/standard/basic_functions.c b/ext/standard/basic_functions.c index c3ad0aad9de15..3517b514420d5 100755 --- a/ext/standard/basic_functions.c +++ b/ext/standard/basic_functions.c @@ -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(); } diff --git a/ext/standard/tests/general_functions/register_shutdown_functions_without_previous_call_frame_01.phpt b/ext/standard/tests/general_functions/register_shutdown_functions_without_previous_call_frame_01.phpt new file mode 100644 index 0000000000000..ee102894cb779 --- /dev/null +++ b/ext/standard/tests/general_functions/register_shutdown_functions_without_previous_call_frame_01.phpt @@ -0,0 +1,15 @@ +--TEST-- +register_shutdown_function() without a previous call frame 01 +--FILE-- + +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 diff --git a/ext/standard/tests/general_functions/register_shutdown_functions_without_previous_call_frame_02.phpt b/ext/standard/tests/general_functions/register_shutdown_functions_without_previous_call_frame_02.phpt new file mode 100644 index 0000000000000..69826ac562e25 --- /dev/null +++ b/ext/standard/tests/general_functions/register_shutdown_functions_without_previous_call_frame_02.phpt @@ -0,0 +1,15 @@ +--TEST-- +register_shutdown_function() without a previous call frame 02 +--FILE-- + +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 diff --git a/ext/standard/tests/general_functions/register_shutdown_functions_without_previous_call_frame_03.phpt b/ext/standard/tests/general_functions/register_shutdown_functions_without_previous_call_frame_03.phpt new file mode 100644 index 0000000000000..dd847b2bb0b6a --- /dev/null +++ b/ext/standard/tests/general_functions/register_shutdown_functions_without_previous_call_frame_03.phpt @@ -0,0 +1,15 @@ +--TEST-- +register_shutdown_function() without a previous call frame 03 +--FILE-- + +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 diff --git a/ext/standard/tests/general_functions/register_shutdown_functions_without_previous_call_frame_04.phpt b/ext/standard/tests/general_functions/register_shutdown_functions_without_previous_call_frame_04.phpt new file mode 100644 index 0000000000000..220af3a67ff97 --- /dev/null +++ b/ext/standard/tests/general_functions/register_shutdown_functions_without_previous_call_frame_04.phpt @@ -0,0 +1,15 @@ +--TEST-- +register_shutdown_function() without a previous call frame 04 +--FILE-- + +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