Skip to content

Commit f689b1b

Browse files
committed
gh-69573: Check return value of msvcrt_putch and msvcrt_putwch
1 parent 7fb315b commit f689b1b

2 files changed

Lines changed: 11 additions & 2 deletions

File tree

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Check return values of ``_putch`` and ``_putwch`` in ``msvcrt.putch`` and ``msvcrt.putwch``.

PC/msvcrtmodule.c

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -330,9 +330,13 @@ static PyObject *
330330
msvcrt_putch_impl(PyObject *module, char char_value)
331331
/*[clinic end generated code: output=92ec9b81012d8f60 input=ec078dd10cb054d6]*/
332332
{
333+
int res;
333334
_Py_BEGIN_SUPPRESS_IPH
334-
_putch(char_value);
335+
res = _putch(char_value);
335336
_Py_END_SUPPRESS_IPH
337+
if (res == EOF) {
338+
return PyErr_SetFromErrno(PyExc_OSError);
339+
}
336340
Py_RETURN_NONE;
337341
}
338342

@@ -351,9 +355,13 @@ static PyObject *
351355
msvcrt_putwch_impl(PyObject *module, int unicode_char)
352356
/*[clinic end generated code: output=a3bd1a8951d28eee input=996ccd0bbcbac4c3]*/
353357
{
358+
wint_t res;
354359
_Py_BEGIN_SUPPRESS_IPH
355-
_putwch(unicode_char);
360+
res = _putwch(unicode_char);
356361
_Py_END_SUPPRESS_IPH
362+
if (res == WEOF) {
363+
return PyErr_SetFromErrno(PyExc_OSError);
364+
}
357365
Py_RETURN_NONE;
358366

359367
}

0 commit comments

Comments
 (0)