Skip to content

Commit 9e7932b

Browse files
committed
Merge branch 'PHP-8.2' into PHP-8.3
* PHP-8.2: Add observer temporary to dl'ed functions
2 parents 16c0e57 + 6f57993 commit 9e7932b

File tree

6 files changed

+94
-2
lines changed

6 files changed

+94
-2
lines changed

NEWS

+2
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@ PHP NEWS
88
(nielsdos)
99
. Fixed bug GH-17101 (AST->string does not reproduce constructor property
1010
promotion correctly). (nielsdos)
11+
. Fixed bug GH-17211 (observer segfault on function loaded with dl()).
12+
(Arnaud)
1113

1214
- Date:
1315
. Fixed bug GH-14709 DatePeriod::__construct() overflow on recurrences.

Zend/zend_API.c

+8-1
Original file line numberDiff line numberDiff line change
@@ -2817,7 +2817,14 @@ ZEND_API zend_result zend_register_functions(zend_class_entry *scope, const zend
28172817
}
28182818
internal_function->type = ZEND_INTERNAL_FUNCTION;
28192819
internal_function->module = EG(current_module);
2820-
internal_function->T = 0;
2820+
if (EG(active) && ZEND_OBSERVER_ENABLED) {
2821+
/* Add an observer temporary to store previous observed frames. This is
2822+
* normally handled by zend_observer_post_startup(), except for
2823+
* functions registered at runtime (EG(active)). */
2824+
internal_function->T = 1;
2825+
} else {
2826+
internal_function->T = 0;
2827+
}
28212828
memset(internal_function->reserved, 0, ZEND_MAX_RESERVED_RESOURCES * sizeof(void*));
28222829

28232830
while (ptr->fname) {

ext/dl_test/dl_test.c

+18
Original file line numberDiff line numberDiff line change
@@ -76,9 +76,27 @@ PHP_INI_BEGIN()
7676
PHP_INI_END()
7777
/* }}} */
7878

79+
PHP_METHOD(DlTest, test)
80+
{
81+
char *var = "World";
82+
size_t var_len = sizeof("World") - 1;
83+
zend_string *retval;
84+
85+
ZEND_PARSE_PARAMETERS_START(0, 1)
86+
Z_PARAM_OPTIONAL
87+
Z_PARAM_STRING(var, var_len)
88+
ZEND_PARSE_PARAMETERS_END();
89+
90+
retval = strpprintf(0, "Hello %s", var);
91+
92+
RETURN_STR(retval);
93+
}
94+
7995
/* {{{ PHP_MINIT_FUNCTION */
8096
PHP_MINIT_FUNCTION(dl_test)
8197
{
98+
register_class_DlTest();
99+
82100
/* Test backwards compatibility */
83101
if (getenv("PHP_DL_TEST_USE_OLD_REGISTER_INI_ENTRIES")) {
84102
zend_register_ini_entries(ini_entries, module_number);

ext/dl_test/dl_test.stub.php

+4
Original file line numberDiff line numberDiff line change
@@ -8,3 +8,7 @@
88
function dl_test_test1(): void {}
99

1010
function dl_test_test2(string $str = ""): string {}
11+
12+
class DlTest {
13+
public function test(string $str = ""): string {}
14+
}

ext/dl_test/dl_test_arginfo.h

+20-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
--TEST--
2+
dl() / observer segfault
3+
--EXTENSIONS--
4+
zend_test
5+
--SKIPIF--
6+
<?php include dirname(__DIR__, 3) . "/dl_test/tests/skip.inc"; ?>
7+
--INI--
8+
zend_test.observer.enabled=1
9+
zend_test.observer.observe_functions=1
10+
zend_test.observer.show_output=1
11+
--FILE--
12+
<?php
13+
14+
if (PHP_OS_FAMILY === 'Windows') {
15+
$loaded = dl('php_dl_test.dll');
16+
} else {
17+
$loaded = dl('dl_test.so');
18+
}
19+
20+
var_dump(dl_test_test2("World!"));
21+
22+
$test = new DlTest();
23+
var_dump($test->test("World!"));
24+
?>
25+
--EXPECTF--
26+
<!-- init '%sgh17211.php' -->
27+
<!-- init dl() -->
28+
<dl>
29+
</dl>
30+
<!-- init dl_test_test2() -->
31+
<dl_test_test2>
32+
</dl_test_test2>
33+
<!-- init var_dump() -->
34+
<var_dump>
35+
string(12) "Hello World!"
36+
</var_dump>
37+
<!-- init DlTest::test() -->
38+
<DlTest::test>
39+
</DlTest::test>
40+
<var_dump>
41+
string(12) "Hello World!"
42+
</var_dump>

0 commit comments

Comments
 (0)