Skip to content

gh-154670: Fix use-after-free in itertools.count via re-entrant step#154671

Open
tonghuaroot wants to merge 4 commits into
python:mainfrom
tonghuaroot:fix-count-reentrant-uaf
Open

gh-154670: Fix use-after-free in itertools.count via re-entrant step#154671
tonghuaroot wants to merge 4 commits into
python:mainfrom
tonghuaroot:fix-count-reentrant-uaf

Conversation

@tonghuaroot

@tonghuaroot tonghuaroot commented Jul 25, 2026

Copy link
Copy Markdown
Contributor

count_nextlong() borrows lz->long_cnt without Py_INCREF, then calls PyNumber_Add which can re-enter via step.__radd__. The inner next() returns the same pointer; when the caller releases it, the outer call holds a dangling pointer.

Fix: Py_NewRef the borrowed value before the callback, Py_SETREF for the swap.

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants