Skip to content

Commit 2578807

Browse files
beberleirioderelftecmb69dstogov
committed
Fix zend_observer_fcall_end_all() accessing dangling pointers
By switching attribute constructor stackframe to be called via trampoline the stack allocation is not causing dangling pointers in the zend_observer API anymore. Co-Authored-By: Florian Sowade <f.sowade@suora.com> Co-Authored-By: Christopher Becker <cmbecker69@gmx.de> Co-Authored-By: Dmitry Stogov <dmitry@zend.com>
1 parent 09165ac commit 2578807

File tree

3 files changed

+69
-0
lines changed

3 files changed

+69
-0
lines changed

ext/reflection/php_reflection.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6315,6 +6315,7 @@ static int call_attribute_constructor(
63156315
dummy_func.type = ZEND_USER_FUNCTION;
63166316
dummy_func.common.fn_flags =
63176317
attr->flags & ZEND_ATTRIBUTE_STRICT_TYPES ? ZEND_ACC_STRICT_TYPES : 0;
6318+
dummy_func.common.fn_flags |= ZEND_ACC_CALL_VIA_TRAMPOLINE;
63186319
dummy_func.op_array.filename = filename;
63196320

63206321
dummy_opline.opcode = ZEND_DO_FCALL;
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
--TEST--
2+
Bug #81430 (Attribute instantiation frame accessing invalid frame pointer)
3+
--INI--
4+
memory_limit=20M
5+
zend_test.observer.enabled=1
6+
zend_test.observer.observe_all=1
7+
--FILE--
8+
<?php
9+
10+
function another_userland() {
11+
return 2 * 2;
12+
}
13+
14+
#[\Attribute]
15+
class A {
16+
private $a;
17+
public function __construct() {
18+
$this->a = another_userland();
19+
}
20+
}
21+
22+
#[A]
23+
function B() {}
24+
25+
$r = new \ReflectionFunction("B");
26+
call_user_func([$r->getAttributes(A::class)[0], 'newInstance']);
27+
?>
28+
--EXPECTF--
29+
<!-- init '%s' -->
30+
<file '%s'>
31+
<!-- init A::__construct() -->
32+
<A::__construct>
33+
<!-- init another_userland() -->
34+
<another_userland>
35+
</another_userland>
36+
</A::__construct>
37+
</file '%s'>
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
--TEST--
2+
Bug #81430 (Attribute instantiation leaves dangling execute_data pointer)
3+
--INI--
4+
memory_limit=20M
5+
zend_test.observer.enabled=1
6+
zend_test.observer.observe_all=1
7+
--FILE--
8+
<?php
9+
10+
#[\Attribute]
11+
class A {
12+
public function __construct() {
13+
array_map("str_repeat", ["\xFF"], [100000000]); // cause a bailout
14+
}
15+
}
16+
17+
#[A]
18+
function B() {}
19+
20+
$r = new \ReflectionFunction("B");
21+
call_user_func([$r->getAttributes(A::class)[0], 'newInstance']);
22+
?>
23+
--EXPECTF--
24+
<!-- init '%s' -->
25+
<file '%s'>
26+
<!-- init A::__construct() -->
27+
<A::__construct>
28+
29+
Fatal error: Allowed memory size of %d bytes exhausted %s in %s on line %d
30+
</A::__construct>
31+
</file '%s'>

0 commit comments

Comments
 (0)