Skip to content

Commit b976bc4

Browse files
committed
Fixed bug #81208
The number of populated positional arguments is argc. i may also include named args and thus try to dtor uninitialized zvals.
1 parent 99c0efc commit b976bc4

File tree

3 files changed

+33
-1
lines changed

3 files changed

+33
-1
lines changed

NEWS

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,10 @@ PHP NEWS
2222
- PCRE:
2323
. Fixed bug #81101 (PCRE2 10.37 shows unexpected result). (Anatol)
2424

25+
- Reflection:
26+
. Fixed bug #81208 (Segmentation fault while create newInstance from
27+
attribute). (Nikita)
28+
2529
17 Jun 2021, PHP 8.0.8
2630

2731
- Core:

ext/reflection/php_reflection.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6435,7 +6435,7 @@ ZEND_METHOD(ReflectionAttribute, newInstance)
64356435
for (uint32_t i = 0; i < attr->data->argc; i++) {
64366436
zval val;
64376437
if (FAILURE == zend_get_attribute_value(&val, attr->data, i, attr->scope)) {
6438-
attribute_ctor_cleanup(&obj, args, i, named_params);
6438+
attribute_ctor_cleanup(&obj, args, argc, named_params);
64396439
RETURN_THROWS();
64406440
}
64416441
if (attr->data->args[i].name) {

ext/reflection/tests/bug81208.phpt

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
--TEST--
2+
Bug #81208: Segmentation fault while create newInstance from attribute
3+
--FILE--
4+
<?php
5+
6+
#[Attribute(Attribute::TARGET_PROPERTY)]
7+
class MyAnnotation
8+
{
9+
public function __construct(public bool $nullable = false) {}
10+
}
11+
12+
class MyClass {
13+
#[MyAnnotation(name: "my_name", type: "integer", nullable: asdasdasd)]
14+
public $property;
15+
}
16+
17+
$z = new ReflectionClass(MyClass::class);
18+
foreach ($z->getProperty("property")->getAttributes() as $attribute) {
19+
try {
20+
$attribute->newInstance();
21+
} catch (Error $e) {
22+
echo $e->getMessage(), "\n";
23+
}
24+
}
25+
26+
?>
27+
--EXPECT--
28+
Undefined constant "asdasdasd"

0 commit comments

Comments
 (0)