Skip to content

gh-155877: Reject an embedded NUL in curses cell text - #155878

Open
fedonman wants to merge 1 commit into
python:mainfrom
fedonman:fix-curses-cell-embedded-nul
Open

gh-155877: Reject an embedded NUL in curses cell text#155878
fedonman wants to merge 1 commit into
python:mainfrom
fedonman:fix-curses-cell-embedded-nul

Conversation

@fedonman

@fedonman fedonman commented Aug 16, 2026

Copy link
Copy Markdown
Contributor

curses.complexchar() and curses.complexstr() now reject a text containing a NUL, and the shared cell converter rejects a NUL inside a multi-character cell, so window.addch() and its siblings no longer keep only the text before it. A lone NUL is still written like addch(0).

$ ./python -m test test_curses -u curses -v -m test_cell_embedded_null_chars
test_cell_embedded_null_chars (test.test_curses.TestCurses.test_cell_embedded_null_chars) ... ok
Total tests: run=1 (filtered)
Result: SUCCESS

$ ./python -m test test_curses -u curses
Total tests: run=169 skipped=3
Result: SUCCESS

No NEWS entry: the cell API has not been released.

setcchar() stops at the first NUL, so a cell text containing one was
silently truncated: complexchar('a\0\u0301') dropped the combining
character, and complexchar('\0') built a cell with no text, whose
repr() is not a valid constructor call and which terminates the
cchar_t array passed to add_wchnstr().

The two cell construction paths, curses_cell_pack() and
complexstr_from_string(), now reject any NUL, and the shared converter
rejects a NUL inside a multi-character cell.  A lone NUL still reaches
the write methods, so addch('\0') keeps writing what addch(0) writes.
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