Check return value of PyObject_AsFileDescriptor() in _Py_DisplaySourceLine() for error

CID 486768
This commit is contained in:
Christian Heimes 2013-07-21 01:53:18 +02:00
commit 8282d749a6
1 changed files with 5 additions and 0 deletions

View File

@ -257,6 +257,11 @@ _Py_DisplaySourceLine(PyObject *f, PyObject *filename, int lineno, int indent)
/* use the right encoding to decode the file as unicode */
fd = PyObject_AsFileDescriptor(binary);
if (fd < 0) {
Py_DECREF(io);
Py_DECREF(binary);
return NULL;
}
found_encoding = PyTokenizer_FindEncodingFilename(fd, filename);
encoding = (found_encoding != NULL) ? found_encoding : "utf-8";
lseek(fd, 0, 0); /* Reset position */