-
Notifications
You must be signed in to change notification settings - Fork 7.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Zend: Fix reference counting for Closures in const-expr
Fixes #17851
- Loading branch information
Showing
3 changed files
with
70 additions
and
1 deletion.
There are no files selected for viewing
9 changes: 9 additions & 0 deletions
9
Zend/tests/closures/closure_const_expr/attributes_autoload.inc
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
<?php | ||
|
||
#[Attr(static function () { })] | ||
#[Attr(static function (...$args) { | ||
var_dump($args); | ||
})] | ||
class C {} | ||
|
||
?> |
57 changes: 57 additions & 0 deletions
57
Zend/tests/closures/closure_const_expr/attributes_autoload.phpt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
--TEST-- | ||
GH-17851: Use-after-free when instantiating autoloaded class with attribute having a Closure parameter. | ||
--EXTENSIONS-- | ||
reflection | ||
--FILE-- | ||
<?php | ||
|
||
spl_autoload_register(static function ($className) { | ||
if ($className === 'C') { | ||
require(__DIR__ . '/attributes_autoload.inc'); | ||
} | ||
}); | ||
|
||
#[Attribute(Attribute::TARGET_CLASS | Attribute::IS_REPEATABLE)] | ||
class Attr { | ||
public function __construct(public Closure $value) { | ||
$value('foo'); | ||
} | ||
} | ||
|
||
foreach ((new ReflectionClass(C::class))->getAttributes() as $reflectionAttribute) { | ||
var_dump($reflectionAttribute->newInstance()); | ||
} | ||
|
||
?> | ||
--EXPECTF-- | ||
object(Attr)#%d (1) { | ||
["value"]=> | ||
object(Closure)#%d (3) { | ||
["name"]=> | ||
string(%d) "{closure:%s:%d}" | ||
["file"]=> | ||
string(%d) "%s" | ||
["line"]=> | ||
int(%d) | ||
} | ||
} | ||
array(1) { | ||
[0]=> | ||
string(3) "foo" | ||
} | ||
object(Attr)#%d (1) { | ||
["value"]=> | ||
object(Closure)#%d (4) { | ||
["name"]=> | ||
string(%d) "{closure:%s:%d}" | ||
["file"]=> | ||
string(%d) "%s" | ||
["line"]=> | ||
int(%d) | ||
["parameter"]=> | ||
array(1) { | ||
["$args"]=> | ||
string(10) "<optional>" | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters