Commit 8a5403dc authored by Victor Stinner's avatar Victor Stinner

Issue #6697: Check that _PyUnicode_AsString() result is not NULL in textio.c

The bug may occurs if locale.getpreferredencoding() returns an encoding with a
surrogate (very unlikely!).
parent 23aea573
......@@ -905,8 +905,11 @@ textiowrapper_init(textio *self, PyObject *args, PyObject *kwds)
Py_CLEAR(self->encoding);
}
}
if (self->encoding != NULL)
if (self->encoding != NULL) {
encoding = _PyUnicode_AsString(self->encoding);
if (encoding == NULL)
goto error;
}
else if (encoding != NULL) {
self->encoding = PyUnicode_FromString(encoding);
if (self->encoding == NULL)
......@@ -935,6 +938,8 @@ textiowrapper_init(textio *self, PyObject *args, PyObject *kwds)
self->writetranslate = (newline == NULL || newline[0] != '\0');
if (!self->readuniversal && self->readnl) {
self->writenl = _PyUnicode_AsString(self->readnl);
if (self->writenl == NULL)
goto error;
if (!strcmp(self->writenl, "\n"))
self->writenl = NULL;
}
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment