gh-148731: Fix crash in Element.iter() on allocation failure#152120
Open
timurmamedov1 wants to merge 1 commit into
Open
gh-148731: Fix crash in Element.iter() on allocation failure#152120timurmamedov1 wants to merge 1 commit into
timurmamedov1 wants to merge 1 commit into
Conversation
01f8b62 to
ca5e3fa
Compare
Initialize parent_stack and parent_stack_used before the fallible PyMem_New call so that elementiter_dealloc does not dereference an uninitialized pointer when the allocation fails.
ca5e3fa to
54c73d2
Compare
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.
create_elementiterallocates anElementIterObjectviaPyObject_GC_New, then attempts to allocateparent_stackviaPyMem_New. If that second allocation fails,Py_DECREF(it)triggerselementiter_dealloc, which readsparent_stack_used(uninitialized garbage fromPyObject_GC_New) and dereferencesparent_stack(NULL), causing a segfault.Fix by initializing
parent_stacktoNULLandparent_stack_usedto0immediately afterPyObject_GC_New, before any operations that can fail.create_elementiterwhen OOM #148731