diff options
author | Serhiy Storchaka <storchaka@gmail.com> | 2023-11-14 20:02:28 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-11-14 20:02:28 (GMT) |
commit | 9302f05f9af07332c414b3c19003efd1b1763cf3 (patch) | |
tree | 496fcbadb2abf8e0db779fa4e942fcfc9a91234c /Modules/_io | |
parent | 0ff6368519ed7542ad8b443de01108690102420a (diff) | |
download | cpython-9302f05f9af07332c414b3c19003efd1b1763cf3.zip cpython-9302f05f9af07332c414b3c19003efd1b1763cf3.tar.gz cpython-9302f05f9af07332c414b3c19003efd1b1763cf3.tar.bz2 |
gh-111942: Fix SystemError in the TextIOWrapper constructor (#112061)
In non-debug more the check for the "errors" argument is skipped,
and then PyUnicode_AsUTF8() can fail, but its result was not checked.
Co-authored-by: Victor Stinner <vstinner@python.org>
Diffstat (limited to 'Modules/_io')
-rw-r--r-- | Modules/_io/textio.c | 8 |
1 files changed, 6 insertions, 2 deletions
diff --git a/Modules/_io/textio.c b/Modules/_io/textio.c index 5c37e99..8d19198 100644 --- a/Modules/_io/textio.c +++ b/Modules/_io/textio.c @@ -1112,6 +1112,10 @@ _io_TextIOWrapper___init___impl(textio *self, PyObject *buffer, else if (io_check_errors(errors)) { return -1; } + const char *errors_str = _PyUnicode_AsUTF8NoNUL(errors); + if (errors_str == NULL) { + return -1; + } if (validate_newline(newline) < 0) { return -1; @@ -1184,11 +1188,11 @@ _io_TextIOWrapper___init___impl(textio *self, PyObject *buffer, /* Build the decoder object */ _PyIO_State *state = find_io_state_by_def(Py_TYPE(self)); self->state = state; - if (_textiowrapper_set_decoder(self, codec_info, PyUnicode_AsUTF8(errors)) != 0) + if (_textiowrapper_set_decoder(self, codec_info, errors_str) != 0) goto error; /* Build the encoder object */ - if (_textiowrapper_set_encoder(self, codec_info, PyUnicode_AsUTF8(errors)) != 0) + if (_textiowrapper_set_encoder(self, codec_info, errors_str) != 0) goto error; /* Finished sorting out the codec details */ |