Skip to content

gh-154781: Zero the in_wstr() buffer in curses - #154782

Open
fedonman wants to merge 2 commits into
python:mainfrom
fedonman:fix-curses-in-wstr-uninit
Open

gh-154781: Zero the in_wstr() buffer in curses#154782
fedonman wants to merge 2 commits into
python:mainfrom
fedonman:fix-curses-in-wstr-uninit

Conversation

@fedonman

@fedonman fedonman commented Jul 27, 2026

Copy link
Copy Markdown
Contributor

winnwstr() only writes the terminating null when it stored at least one character, so
in_wstr(y, x, 0) read the result from uninitialized memory and usually raised
ValueError: character U+xxxxxxxx is not in range. Use PyMem_Calloc, like in_wchstr()
already does since gh-152503.

in_wstr() is new in 3.16, so there is no NEWS entry.

winnwstr() only writes the terminating null when it stored at least one
character, so with n of 0 the result was read from uninitialized memory. Use
PyMem_Calloc, like in_wchstr() already does.
Comment thread Modules/_cursesmodule.c
PyMem_Free(buf);
return Py_GetConstant(Py_CONSTANT_EMPTY_STR);
}
PyObject *res = PyUnicode_FromWideChar(buf, -1);

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should not this be enough?

Suggested change
PyObject *res = PyUnicode_FromWideChar(buf, rtn);

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