Skip to content

gh-152682: Fix NULL dereference on OOM in symtable_visit_type_param_bound_or_default#152684

Merged
sobolevn merged 1 commit into
python:mainfrom
petrvaganoff:dev
Jun 30, 2026
Merged

gh-152682: Fix NULL dereference on OOM in symtable_visit_type_param_bound_or_default#152684
sobolevn merged 1 commit into
python:mainfrom
petrvaganoff:dev

Conversation

@petrvaganoff

@petrvaganoff petrvaganoff commented Jun 30, 2026

Copy link
Copy Markdown
Contributor

When a reserved name (e.g. __classdict__) is used as a type parameter,
symtable_visit_type_param_bound_or_default() calls PyUnicode_FromFormat()
to build the SyntaxError message. If the allocation fails and returns NULL,
the subsequent PyErr_SetObject(PyExc_SyntaxError, NULL) and Py_DECREF(NULL)
calls dereference the null pointer, causing a segfault.

Fix by returning 0 immediately when PyUnicode_FromFormat() returns NULL,
which propagates the MemoryError already set by PyUnicode_FromFormat().

The bug was introduced in gh-128632 (commit 891c61c).

Found by static analyzer Svace (ISP RAS).

  • Add a NEWS entry in Misc/NEWS.d/
  • Add regression test (test_disallowed_type_param_names_oom)

Loading
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants