Fix use-after-free in extract() EXTR_REFS collision modes#155
Closed
iliaal wants to merge 1 commit into
Closed
Conversation
The phpGH-18209 fix guarded only php_extract_ref_overwrite. The other five per-collision-mode helpers (if_exists, prefix_if_exists, prefix_same, prefix_all, prefix_invalid), split out when extract() was refactored, kept the pre-fix order: they dropped the old value of orig_var before writing the new reference. A destructor run by that drop can unset the symbol being written, so the following ZVAL_REF wrote into freed memory. Apply the same swap-then-dtor already used by php_extract_ref_overwrite: copy the old value aside, write the reference, then drop the copy. Fixes phpGH-18209
a9b7211 to
0247183
Compare
Owner
Author
|
Submitted upstream as php#22696. |
This file contains hidden or 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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
The phpGH-18209 fix guarded only php_extract_ref_overwrite. The other five per-collision-mode helpers (if_exists, prefix_if_exists, prefix_same, prefix_all, prefix_invalid), split out when extract() was refactored, kept the pre-fix order: they dropped the old value of orig_var before writing the new reference, so a destructor run by that drop that frees the target symbol makes the following ZVAL_REF a use-after-free. This applies the same swap-then-dtor already used by php_extract_ref_overwrite (copy the old value aside, write the reference, then drop the copy). Reproduces with extract($a, EXTR_REFS | EXTR_IF_EXISTS) when the target variable holds an object whose destructor unsets it.