]> git.ipfire.org Git - thirdparty/Python/cpython.git/commit
gh-152682: Fix NULL dereference on OOM in `symtable_visit_type_param_bound_or_default...
authorPetr Vaganov <petrvaganoff@gmail.com>
Tue, 30 Jun 2026 14:45:25 +0000 (21:45 +0700)
committerGitHub <noreply@github.com>
Tue, 30 Jun 2026 14:45:25 +0000 (14:45 +0000)
commit10ed03edf128ed1101ab8d04bcd715f2033fec55
tree978adbc2738eb092ce3865f88f614a027044bedd
parent2303eea150602874d55d965eb3f83d6e80649118
gh-152682: Fix NULL dereference on OOM in `symtable_visit_type_param_bound_or_default` (#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 gh-128632 (commit 891c61c).
Lib/test/test_syntax.py
Misc/NEWS.d/next/Core_and_Builtins/2026-06-30-14-00-00.gh-issue-152682.yId7e5.rst [new file with mode: 0644]
Python/symtable.c