From f689b1b6a11f40162160554e008bc328532bd77e Mon Sep 17 00:00:00 2001 From: Abdullah Masood Date: Mon, 17 Aug 2026 17:39:06 +0500 Subject: [PATCH] gh-69573: Check return value of msvcrt_putch and msvcrt_putwch --- .../2026-08-17-17-38-00.gh-issue-69573.abcdef.rst | 1 + PC/msvcrtmodule.c | 12 ++++++++++-- 2 files changed, 11 insertions(+), 2 deletions(-) create mode 100644 Misc/NEWS.d/next/Windows/2026-08-17-17-38-00.gh-issue-69573.abcdef.rst diff --git a/Misc/NEWS.d/next/Windows/2026-08-17-17-38-00.gh-issue-69573.abcdef.rst b/Misc/NEWS.d/next/Windows/2026-08-17-17-38-00.gh-issue-69573.abcdef.rst new file mode 100644 index 000000000000000..366fe127ff97a2b --- /dev/null +++ b/Misc/NEWS.d/next/Windows/2026-08-17-17-38-00.gh-issue-69573.abcdef.rst @@ -0,0 +1 @@ +Check return values of ``_putch`` and ``_putwch`` in ``msvcrt.putch`` and ``msvcrt.putwch``. diff --git a/PC/msvcrtmodule.c b/PC/msvcrtmodule.c index 8826e7e85a7f5ab..55de2ec0b7e13c9 100644 --- a/PC/msvcrtmodule.c +++ b/PC/msvcrtmodule.c @@ -330,9 +330,13 @@ static PyObject * msvcrt_putch_impl(PyObject *module, char char_value) /*[clinic end generated code: output=92ec9b81012d8f60 input=ec078dd10cb054d6]*/ { + int res; _Py_BEGIN_SUPPRESS_IPH - _putch(char_value); + res = _putch(char_value); _Py_END_SUPPRESS_IPH + if (res == EOF) { + return PyErr_SetFromErrno(PyExc_OSError); + } Py_RETURN_NONE; } @@ -351,9 +355,13 @@ static PyObject * msvcrt_putwch_impl(PyObject *module, int unicode_char) /*[clinic end generated code: output=a3bd1a8951d28eee input=996ccd0bbcbac4c3]*/ { + wint_t res; _Py_BEGIN_SUPPRESS_IPH - _putwch(unicode_char); + res = _putwch(unicode_char); _Py_END_SUPPRESS_IPH + if (res == WEOF) { + return PyErr_SetFromErrno(PyExc_OSError); + } Py_RETURN_NONE; }