bpo-32402: io: Add missing NULL check. (GH-4971)

_PyUnicode_FromId() may return NULL.

Reported by coverity scan: CID 1426868, 1426867.
This commit is contained in:
INADA Naoki 2017-12-24 10:29:19 +09:00 committed by GitHub
parent 719ccbca69
commit 4856b0f34a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 6 additions and 0 deletions

View File

@ -1037,6 +1037,9 @@ _io_TextIOWrapper___init___impl(textio *self, PyObject *buffer,
if (errors == Py_None) {
errors = _PyUnicode_FromId(&PyId_strict); /* borrowed */
if (errors == NULL) {
return -1;
}
}
else if (!PyUnicode_Check(errors)) {
// Check 'errors' argument here because Argument Clinic doesn't support
@ -1249,6 +1252,9 @@ textiowrapper_change_encoding(textio *self, PyObject *encoding,
}
else if (errors == Py_None) {
errors = _PyUnicode_FromId(&PyId_strict);
if (errors == NULL) {
return -1;
}
}
const char *c_errors = PyUnicode_AsUTF8(errors);