1
0
mirror of https://github.com/php/php-src.git synced 2026-03-24 00:02:20 +01:00

Merge branch 'PHP-8.2' into PHP-8.3

* PHP-8.2:
  Fixed GH-16233: Observer segfault when calling user function in internal function via trampoline
This commit is contained in:
Niels Dossche
2024-10-07 17:17:27 +02:00
6 changed files with 81 additions and 2 deletions

2
NEWS
View File

@@ -23,6 +23,8 @@ PHP NEWS
nested generator frame). (ilutov)
. Fixed bug GH-15866 (Core dumped in Zend/zend_generators.c). (Arnaud)
. Fixed bug GH-16188 (Assertion failure in Zend/zend_exceptions.c). (Arnaud)
. Fixed bug GH-16233 (Observer segfault when calling user function in
internal function via trampoline). (nielsdos)
- DOM:
. Fixed bug GH-16039 (Segmentation fault (access null pointer) in

View File

@@ -30,6 +30,7 @@
#include "zend_closures.h"
#include "zend_compile.h"
#include "zend_hash.h"
#include "zend_observer.h"
#define DEBUG_OBJECT_HANDLERS 0
@@ -1358,7 +1359,8 @@ ZEND_API zend_function *zend_get_call_trampoline_func(const zend_class_entry *ce
* value so that it doesn't contain garbage when the engine allocates space for the next stack
* frame. This didn't cause any issues until now due to "lucky" structure layout. */
func->last_var = 0;
func->T = (fbc->type == ZEND_USER_FUNCTION)? MAX(fbc->op_array.last_var + fbc->op_array.T, 2) : 2;
uint32_t min_T = 2 + ZEND_OBSERVER_ENABLED;
func->T = (fbc->type == ZEND_USER_FUNCTION)? MAX(fbc->op_array.last_var + fbc->op_array.T, min_T) : min_T;
func->filename = (fbc->type == ZEND_USER_FUNCTION)? fbc->op_array.filename : ZSTR_EMPTY_ALLOC();
func->line_start = (fbc->type == ZEND_USER_FUNCTION)? fbc->op_array.line_start : 0;
func->line_end = (fbc->type == ZEND_USER_FUNCTION)? fbc->op_array.line_end : 0;

View File

@@ -1039,6 +1039,23 @@ static ZEND_METHOD(_ZendTestMagicCall, __call)
RETURN_ARR(zend_new_pair(&name_zv, arguments));
}
static ZEND_METHOD(_ZendTestMagicCallForward, __call)
{
zend_string *name;
zval *arguments;
ZEND_PARSE_PARAMETERS_START(2, 2)
Z_PARAM_STR(name)
Z_PARAM_ARRAY(arguments)
ZEND_PARSE_PARAMETERS_END();
ZEND_IGNORE_VALUE(arguments);
zval func;
ZVAL_STR(&func, name);
call_user_function(NULL, NULL, &func, return_value, 0, NULL);
}
PHP_INI_BEGIN()
STD_PHP_INI_BOOLEAN("zend_test.replace_zend_execute_ex", "0", PHP_INI_SYSTEM, OnUpdateBool, replace_zend_execute_ex, zend_zend_test_globals, zend_test_globals)
STD_PHP_INI_BOOLEAN("zend_test.register_passes", "0", PHP_INI_SYSTEM, OnUpdateBool, register_passes, zend_zend_test_globals, zend_test_globals)
@@ -1225,6 +1242,8 @@ PHP_MINIT_FUNCTION(zend_test)
zend_test_magic_call = register_class__ZendTestMagicCall();
register_class__ZendTestMagicCallForward();
zend_register_functions(NULL, ext_function_legacy, NULL, EG(current_module)->type);
// Loading via dl() not supported with the observer API

View File

@@ -62,6 +62,11 @@ namespace {
public function __call(string $name, array $args): mixed {}
}
class _ZendTestMagicCallForward
{
public function __call(string $name, array $args): mixed {}
}
class _ZendTestChildClass extends _ZendTestClass
{
public function returnsThrowable(): Exception {}

View File

@@ -1,5 +1,5 @@
/* This is a generated file, edit the .stub.php file instead.
* Stub hash: 127c7004a014495353135df6d0b6658446ae040b */
* Stub hash: 4b349d5ac8e8daba565b57a091fc463d3132d37d */
ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_zend_test_array_return, 0, 0, IS_ARRAY, 0)
ZEND_END_ARG_INFO()
@@ -197,6 +197,8 @@ ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_class__ZendTestMagicCall___call,
ZEND_ARG_TYPE_INFO(0, args, IS_ARRAY, 0)
ZEND_END_ARG_INFO()
#define arginfo_class__ZendTestMagicCallForward___call arginfo_class__ZendTestMagicCall___call
ZEND_BEGIN_ARG_WITH_RETURN_OBJ_INFO_EX(arginfo_class__ZendTestChildClass_returnsThrowable, 0, 0, Exception, 0)
ZEND_END_ARG_INFO()
@@ -296,6 +298,7 @@ static ZEND_METHOD(_ZendTestClass, returnsThrowable);
static ZEND_METHOD(_ZendTestClass, variadicTest);
static ZEND_METHOD(_ZendTestClass, takesUnionType);
static ZEND_METHOD(_ZendTestMagicCall, __call);
static ZEND_METHOD(_ZendTestMagicCallForward, __call);
static ZEND_METHOD(_ZendTestChildClass, returnsThrowable);
static ZEND_METHOD(ZendAttributeTest, testMethod);
static ZEND_METHOD(_ZendTestTrait, testMethod);
@@ -397,6 +400,12 @@ static const zend_function_entry class__ZendTestMagicCall_methods[] = {
};
static const zend_function_entry class__ZendTestMagicCallForward_methods[] = {
ZEND_ME(_ZendTestMagicCallForward, __call, arginfo_class__ZendTestMagicCallForward___call, ZEND_ACC_PUBLIC)
ZEND_FE_END
};
static const zend_function_entry class__ZendTestChildClass_methods[] = {
ZEND_ME(_ZendTestChildClass, returnsThrowable, arginfo_class__ZendTestChildClass_returnsThrowable, ZEND_ACC_PUBLIC)
ZEND_FE_END
@@ -652,6 +661,16 @@ static zend_class_entry *register_class__ZendTestMagicCall(void)
return class_entry;
}
static zend_class_entry *register_class__ZendTestMagicCallForward(void)
{
zend_class_entry ce, *class_entry;
INIT_CLASS_ENTRY(ce, "_ZendTestMagicCallForward", class__ZendTestMagicCallForward_methods);
class_entry = zend_register_internal_class_ex(&ce, NULL);
return class_entry;
}
static zend_class_entry *register_class__ZendTestChildClass(zend_class_entry *class_entry__ZendTestClass)
{
zend_class_entry ce, *class_entry;

View File

@@ -0,0 +1,32 @@
--TEST--
GH-16233 (Observer segfault when calling user function in internal function via trampoline)
--EXTENSIONS--
zend_test
--INI--
zend_test.observer.enabled=1
zend_test.observer.show_output=1
zend_test.observer.observe_all=1
--FILE--
<?php
function callee() {
echo "in callee\n";
}
$test = new _ZendTestMagicCallForward;
$test->callee();
echo "done\n";
?>
--EXPECTF--
<!-- init '%sgh16233.php' -->
<file '%sgh16233.php'>
<!-- init _ZendTestMagicCallForward::__call() -->
<_ZendTestMagicCallForward::__call>
<!-- init callee() -->
<callee>
in callee
</callee>
</_ZendTestMagicCallForward::__call>
done
</file '%sgh16233.php'>