-
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.
Fix GH-13612: Corrupted memory in destructor with weak references
Inside `zend_object_std_dtor` the weakrefs are notified after the destruction of properties already took place. In this test case, the destructor of an anon class will be invoked due to the property destruction. That class has a weak reference to its parent. This means that the destructor can access parent properties that already have been destroyed, resulting in a UAF. Fix this by notifying the weakrefs at the start of the object's destruction. Closes GH-13613.
- Loading branch information
Showing
3 changed files
with
47 additions
and
4 deletions.
There are no files selected for viewing
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
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,39 @@ | ||
--TEST-- | ||
GH-13612 (Corrupted memory in destructor with weak references) | ||
--FILE-- | ||
<?php | ||
|
||
class WeakAnalysingMapRepro | ||
{ | ||
public array $destroyed = []; | ||
public array $ownerDestructorHandlers = []; | ||
|
||
public function __construct() | ||
{ | ||
$handler = new class($this) { | ||
private \WeakReference $weakAnalysingMap; | ||
|
||
public function __construct(WeakAnalysingMapRepro $analysingMap) | ||
{ | ||
$this->weakAnalysingMap = \WeakReference::create($analysingMap); | ||
} | ||
|
||
public function __destruct() | ||
{ | ||
var_dump($this->weakAnalysingMap->get()); | ||
} | ||
}; | ||
|
||
$this->destroyed[] = 1; | ||
$this->ownerDestructorHandlers[] = $handler; | ||
} | ||
} | ||
|
||
new WeakAnalysingMapRepro(); | ||
|
||
echo "Done\n"; | ||
|
||
?> | ||
--EXPECT-- | ||
NULL | ||
Done |
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