gh-154749: Reject a terminal-less screen in curses.set_term() - #154750
Merged
serhiy-storchaka merged 4 commits intoJul 27, 2026
Conversation
curses.set_term() accepted a screen returned by new_prescr(), which has no terminal attached. Making such a screen current left curses without a terminal, and the next window refresh dereferenced NULL and crashed the interpreter. set_term() now raises curses.error for a screen with no standard window, which is exactly a new_prescr() screen. The documentation already said the argument comes from newterm().
Documentation build overview
|
serhiy-storchaka
self-requested a review
July 27, 2026 12:35
Both from review: the test uses the existing requires_curses_func helper, and the NEWS entry goes away because set_term() and new_prescr() are both new in 3.16 and unreleased, so the crash was never reachable by a user.
serhiy-storchaka
enabled auto-merge (squash)
July 27, 2026 18:26
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
curses.set_term()only checked that its argument is a screen that has not beendeleted, so it also accepted a screen from
curses.new_prescr(). That screen has noterminal attached, and once it was made current the next window refresh dereferenced
NULL inside curses and killed the interpreter:
set_term()now raisescurses.errorwhen the screen has no standard window, which isexactly what a
new_prescr()screen is. The documentation already described the argumentas a screen returned by
newterm(), so this makes the code match, and the docs nowmention the exception.
Both functions are new in 3.16 (gh-90092, GH-151748), so no released version is affected
and there is no NEWS entry.
The same reproducer after the change:
Tests: