Skip to content

Uaf in SplObjectStorage::removeAllExcept() with custom getHash() #21831

Description

@iluuu1994

Description

Originally reported by @kdsjZh.

The following code:

<?phpclass S extends SplObjectStorage { public$other; publicfunctiongetHash($obj): string { if ($this->other) { $this->other->offsetUnset($obj); // free element $this->other = null; }
return"x"; // not in this storage -> enter if-block 
} }
$storage = newSplObjectStorage(); $obj = newstdClass();
$storage->offsetSet($obj);
$filter = newS(); $filter->other = $storage;
$storage->removeAllExcept($filter); // UAF here

PHP Version

-

Operating System

No response

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions