Skip to content

Commit 0338008

Browse files
committed
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
2 parents a774704 + e715dd0 commit 0338008

File tree

6 files changed

+81
-2
lines changed

6 files changed

+81
-2
lines changed

NEWS

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@ PHP NEWS
2323
nested generator frame). (ilutov)
2424
. Fixed bug GH-15866 (Core dumped in Zend/zend_generators.c). (Arnaud)
2525
. Fixed bug GH-16188 (Assertion failure in Zend/zend_exceptions.c). (Arnaud)
26+
. Fixed bug GH-16233 (Observer segfault when calling user function in
27+
internal function via trampoline). (nielsdos)
2628

2729
- DOM:
2830
. Fixed bug GH-16039 (Segmentation fault (access null pointer) in

Zend/zend_object_handlers.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
#include "zend_closures.h"
3131
#include "zend_compile.h"
3232
#include "zend_hash.h"
33+
#include "zend_observer.h"
3334

3435
#define DEBUG_OBJECT_HANDLERS 0
3536

@@ -1358,7 +1359,8 @@ ZEND_API zend_function *zend_get_call_trampoline_func(const zend_class_entry *ce
13581359
* value so that it doesn't contain garbage when the engine allocates space for the next stack
13591360
* frame. This didn't cause any issues until now due to "lucky" structure layout. */
13601361
func->last_var = 0;
1361-
func->T = (fbc->type == ZEND_USER_FUNCTION)? MAX(fbc->op_array.last_var + fbc->op_array.T, 2) : 2;
1362+
uint32_t min_T = 2 + ZEND_OBSERVER_ENABLED;
1363+
func->T = (fbc->type == ZEND_USER_FUNCTION)? MAX(fbc->op_array.last_var + fbc->op_array.T, min_T) : min_T;
13621364
func->filename = (fbc->type == ZEND_USER_FUNCTION)? fbc->op_array.filename : ZSTR_EMPTY_ALLOC();
13631365
func->line_start = (fbc->type == ZEND_USER_FUNCTION)? fbc->op_array.line_start : 0;
13641366
func->line_end = (fbc->type == ZEND_USER_FUNCTION)? fbc->op_array.line_end : 0;

ext/zend_test/test.c

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1039,6 +1039,23 @@ static ZEND_METHOD(_ZendTestMagicCall, __call)
10391039
RETURN_ARR(zend_new_pair(&name_zv, arguments));
10401040
}
10411041

1042+
static ZEND_METHOD(_ZendTestMagicCallForward, __call)
1043+
{
1044+
zend_string *name;
1045+
zval *arguments;
1046+
1047+
ZEND_PARSE_PARAMETERS_START(2, 2)
1048+
Z_PARAM_STR(name)
1049+
Z_PARAM_ARRAY(arguments)
1050+
ZEND_PARSE_PARAMETERS_END();
1051+
1052+
ZEND_IGNORE_VALUE(arguments);
1053+
1054+
zval func;
1055+
ZVAL_STR(&func, name);
1056+
call_user_function(NULL, NULL, &func, return_value, 0, NULL);
1057+
}
1058+
10421059
PHP_INI_BEGIN()
10431060
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)
10441061
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)
12251242

12261243
zend_test_magic_call = register_class__ZendTestMagicCall();
12271244

1245+
register_class__ZendTestMagicCallForward();
1246+
12281247
zend_register_functions(NULL, ext_function_legacy, NULL, EG(current_module)->type);
12291248

12301249
// Loading via dl() not supported with the observer API

ext/zend_test/test.stub.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,11 @@ class _ZendTestMagicCall
6262
public function __call(string $name, array $args): mixed {}
6363
}
6464

65+
class _ZendTestMagicCallForward
66+
{
67+
public function __call(string $name, array $args): mixed {}
68+
}
69+
6570
class _ZendTestChildClass extends _ZendTestClass
6671
{
6772
public function returnsThrowable(): Exception {}

ext/zend_test/test_arginfo.h

Lines changed: 20 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

ext/zend_test/tests/gh16233.phpt

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
--TEST--
2+
GH-16233 (Observer segfault when calling user function in internal function via trampoline)
3+
--EXTENSIONS--
4+
zend_test
5+
--INI--
6+
zend_test.observer.enabled=1
7+
zend_test.observer.show_output=1
8+
zend_test.observer.observe_all=1
9+
--FILE--
10+
<?php
11+
12+
function callee() {
13+
echo "in callee\n";
14+
}
15+
16+
$test = new _ZendTestMagicCallForward;
17+
$test->callee();
18+
echo "done\n";
19+
20+
?>
21+
--EXPECTF--
22+
<!-- init '%sgh16233.php' -->
23+
<file '%sgh16233.php'>
24+
<!-- init _ZendTestMagicCallForward::__call() -->
25+
<_ZendTestMagicCallForward::__call>
26+
<!-- init callee() -->
27+
<callee>
28+
in callee
29+
</callee>
30+
</_ZendTestMagicCallForward::__call>
31+
done
32+
</file '%sgh16233.php'>

0 commit comments

Comments
 (0)