-
Notifications
You must be signed in to change notification settings - Fork 7.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix GH-14639: Member access within null pointer in ext/spl/spl_observ…
…er.c `spl_object_storage_attach_handle` creates an entry already, but only fills it in at the end with `spl_object_storage_create_element` which allocates memory. In this case the allocation fails and we're left with a NULL slot. Doing the allocation first isn't an option because we want to check whether the slot is occupied before allocating memory. The simplest solution is to set the entry to NULL and check for a NULL pointer upon destruction. Closes GH-14849.
- Loading branch information
Showing
3 changed files
with
33 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
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,21 @@ | ||
--TEST-- | ||
GH-14639 (Member access within null pointer in ext/spl/spl_observer.c) | ||
--INI-- | ||
memory_limit=2M | ||
--SKIPIF-- | ||
<?php | ||
if (getenv("USE_ZEND_ALLOC") === "0") { | ||
die("skip Zend MM disabled"); | ||
} | ||
?> | ||
--FILE-- | ||
<?php | ||
$b = new SplObjectStorage(); | ||
for ($i = 10000; $i > 0; $i--) { | ||
$object = new StdClass(); | ||
$object->a = str_repeat("a", 2); | ||
$b->attach($object); | ||
} | ||
?> | ||
--EXPECTF-- | ||
Fatal error: Allowed memory size of %d bytes exhausted%s(tried to allocate %d bytes) in %s on line %d |