Check return value of lseek() in _Py_DisplaySourceLine().

Also use portable SEEK_SET instead of 0.
CID 1040639
This commit is contained in:
Christian Heimes 2013-07-21 02:12:35 +02:00
parent c731bbe665
commit 1f34729f42
1 changed files with 7 additions and 1 deletions

View File

@ -262,7 +262,13 @@ _Py_DisplaySourceLine(PyObject *f, PyObject *filename, int lineno, int indent)
}
found_encoding = PyTokenizer_FindEncodingFilename(fd, filename);
encoding = (found_encoding != NULL) ? found_encoding : "utf-8";
lseek(fd, 0, 0); /* Reset position */
/* Reset position */
if (lseek(fd, 0, SEEK_SET) == (off_t)-1) {
Py_DECREF(io);
Py_DECREF(binary);
PyMem_FREE(found_encoding);
return PyErr_SetFromErrnoWithFilenameObject(PyExc_IOError, filename);
}
fob = _PyObject_CallMethodId(io, &PyId_TextIOWrapper, "Os", binary, encoding);
Py_DECREF(io);
Py_DECREF(binary);