Skip to content

gh-151695: Fix use-after-free of the curses screen encoding#151696

Merged
serhiy-storchaka merged 1 commit into
python:mainfrom
serhiy-storchaka:curses-screen-encoding-uaf
Jun 19, 2026
Merged

gh-151695: Fix use-after-free of the curses screen encoding#151696
serhiy-storchaka merged 1 commit into
python:mainfrom
serhiy-storchaka:curses-screen-encoding-uaf

Conversation

@serhiy-storchaka

Copy link
Copy Markdown
Member

The module-global curses_screen_encoding stored a borrowed pointer to the encoding string owned by the window object that the first initscr() call returns. That window object can be deallocated while unctrl() and ungetch() — which have no window of their own — still use the pointer to encode non-ASCII characters, so they end up reading freed memory.

This keeps a private copy of the encoding instead, refreshed on every initscr() and released when the module is torn down.

🤖 Generated with Claude Code

The module-global curses_screen_encoding stored a borrowed pointer to the
encoding owned by the window returned by the first initscr() call.  That
window can be deallocated while unctrl() and ungetch(), which have no window
of their own, still use the pointer to encode non-ASCII characters.

Keep a private copy of the encoding instead.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@serhiy-storchaka serhiy-storchaka added needs backport to 3.13 bugs and security fixes needs backport to 3.14 bugs and security fixes needs backport to 3.15 pre-release feature fixes, bugs and security fixes labels Jun 19, 2026
@serhiy-storchaka serhiy-storchaka enabled auto-merge (squash) June 19, 2026 08:25
@serhiy-storchaka serhiy-storchaka merged commit 551f8e1 into python:main Jun 19, 2026
106 of 108 checks passed
@miss-islington-app

Copy link
Copy Markdown

Thanks @serhiy-storchaka for the PR 🌮🎉.. I'm working now to backport this PR to: 3.13, 3.14, 3.15.
🐍🍒⛏🤖

@miss-islington-app

Copy link
Copy Markdown

Sorry, @serhiy-storchaka, I could not cleanly backport this to 3.14 due to a conflict.
Please backport using cherry_picker on command line.

cherry_picker 551f8e16f8bb38a1e9c6df259a2a0969493de070 3.14

@miss-islington-app

Copy link
Copy Markdown

Sorry, @serhiy-storchaka, I could not cleanly backport this to 3.13 due to a conflict.
Please backport using cherry_picker on command line.

cherry_picker 551f8e16f8bb38a1e9c6df259a2a0969493de070 3.13

@bedevere-app

bedevere-app Bot commented Jun 19, 2026

Copy link
Copy Markdown

GH-151703 is a backport of this pull request to the 3.15 branch.

@bedevere-app bedevere-app Bot removed the needs backport to 3.15 pre-release feature fixes, bugs and security fixes label Jun 19, 2026
@bedevere-app

bedevere-app Bot commented Jun 19, 2026

Copy link
Copy Markdown

GH-151706 is a backport of this pull request to the 3.14 branch.

@bedevere-app bedevere-app Bot removed the needs backport to 3.14 bugs and security fixes label Jun 19, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

needs backport to 3.13 bugs and security fixes

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant