[3.15] gh-152682: Fix NULL dereference on OOM in symtable_visit_type_param_bound_or_default (GH-152684)#152695
Open
miss-islington wants to merge 1 commit into
Open
[3.15] gh-152682: Fix NULL dereference on OOM in symtable_visit_type_param_bound_or_default (GH-152684)#152695miss-islington wants to merge 1 commit into
symtable_visit_type_param_bound_or_default (GH-152684)#152695miss-islington wants to merge 1 commit into
Conversation
…param_bound_or_default` (pythonGH-152684) In `symtable_visit_type_param_bound_or_default()`, when a reserved name (e.g. `__classdict__`) is used as a type parameter, `PyUnicode_FromFormat()` is called to build the SyntaxError message. If the allocation fails and returns NULL, the subsequent `PyErr_SetObject()` and `Py_DECREF()` calls would dereference NULL, causing a segfault. Fix by returning 0 immediately when `PyUnicode_FromFormat()` returns NULL. This propagates the MemoryError set by `PyUnicode_FromFormat()`. The bug was introduced in pythongh-128632 (commit 891c61c). (cherry picked from commit 10ed03e) Co-authored-by: Petr Vaganov <petrvaganoff@gmail.com>
Member
|
Disabling till #152684 (comment) is decided. |
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.
In
symtable_visit_type_param_bound_or_default(), when a reserved name(e.g.
__classdict__) is used as a type parameter,PyUnicode_FromFormat()is called to build the SyntaxError message. If the allocation fails and
returns NULL, the subsequent
PyErr_SetObject()andPy_DECREF()callswould dereference NULL, causing a segfault.
Fix by returning 0 immediately when
PyUnicode_FromFormat()returns NULL.This propagates the MemoryError set by
PyUnicode_FromFormat().The bug was introduced in gh-128632 (commit 891c61c).
(cherry picked from commit 10ed03e)
Co-authored-by: Petr Vaganov petrvaganoff@gmail.com