gh-152682: Fix NULL dereference on OOM in `symtable_visit_type_param_… · python/cpython@10ed03e · GitHub
Skip to content

Commit 10ed03e

Browse files
authored
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).
1 parent 2303eea commit 10ed03e

3 files changed

Lines changed: 23 additions & 0 deletions

File tree

Lib/test/test_syntax.py

Lines changed: 17 additions & 0 deletions
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
Fix NULL pointer dereference in :func:`compile` when a reserved name (e.g.
2+
``__classdict__``) is used as a type parameter name and memory allocation
3+
fails while formatting the error message.

Python/symtable.c

Lines changed: 3 additions & 0 deletions

0 commit comments

Comments
 (0)