]> granicus.if.org Git - python/commitdiff
bpo-32402: io: Add missing NULL check. (GH-4971)
authorINADA Naoki <methane@users.noreply.github.com>
Sun, 24 Dec 2017 01:29:19 +0000 (10:29 +0900)
committerGitHub <noreply@github.com>
Sun, 24 Dec 2017 01:29:19 +0000 (10:29 +0900)
_PyUnicode_FromId() may return NULL.

Reported by coverity scan: CID 14268681426867.

Modules/_io/textio.c

index 6800d2dd253531fec66d52ec8d3e49ebee6c98c4..d776b5de69910de95b2c2137396c523ad792a32e 100644 (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);