-
Notifications
You must be signed in to change notification settings - Fork 7.9k
Fix use after free during shutdown destruction #18834
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 3 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
--TEST-- | ||
Bug #18833 (Use after free with weakmaps dependent on destruction order) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nit: For bugs on github, it's supposed to be GH-18833 instead of a pound sign. I'll fix this in the merge |
||
--FILE-- | ||
<?php | ||
|
||
class a { | ||
public static WeakMap $map; | ||
public static Generator $storage; | ||
} | ||
|
||
a::$map = new WeakMap; | ||
|
||
$closure = function () { | ||
$obj = new a; | ||
a::$map[$obj] = true; | ||
yield $obj; | ||
}; | ||
a::$storage = $closure(); | ||
a::$storage->current(); | ||
|
||
echo "ok\n"; | ||
?> | ||
--EXPECT-- | ||
ok |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -97,33 +97,17 @@ ZEND_API void ZEND_FASTCALL zend_objects_store_free_object_storage(zend_objects_ | |
end = objects->object_buckets + 1; | ||
obj_ptr = objects->object_buckets + objects->top; | ||
|
||
if (fast_shutdown) { | ||
do { | ||
obj_ptr--; | ||
obj = *obj_ptr; | ||
if (IS_OBJ_VALID(obj)) { | ||
if (!(OBJ_FLAGS(obj) & IS_OBJ_FREE_CALLED)) { | ||
GC_ADD_FLAGS(obj, IS_OBJ_FREE_CALLED); | ||
if (obj->handlers->free_obj != zend_object_std_dtor) { | ||
GC_ADDREF(obj); | ||
obj->handlers->free_obj(obj); | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We skipped The problem was introduced by weak references that added notification in |
||
} | ||
} | ||
} while (obj_ptr != end); | ||
} else { | ||
do { | ||
obj_ptr--; | ||
obj = *obj_ptr; | ||
if (IS_OBJ_VALID(obj)) { | ||
if (!(OBJ_FLAGS(obj) & IS_OBJ_FREE_CALLED)) { | ||
GC_ADD_FLAGS(obj, IS_OBJ_FREE_CALLED); | ||
GC_ADDREF(obj); | ||
obj->handlers->free_obj(obj); | ||
} | ||
do { | ||
obj_ptr--; | ||
obj = *obj_ptr; | ||
if (IS_OBJ_VALID(obj)) { | ||
if (!(OBJ_FLAGS(obj) & IS_OBJ_FREE_CALLED)) { | ||
GC_ADD_FLAGS(obj, IS_OBJ_FREE_CALLED); | ||
GC_ADDREF(obj); | ||
obj->handlers->free_obj(obj); | ||
} | ||
} while (obj_ptr != end); | ||
} | ||
} | ||
} while (obj_ptr != end); | ||
} | ||
|
||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Note for self: move this entry