diff options
author | Christian Heimes <christian@cheimes.de> | 2013-07-21 02:12:35 +0200 |
---|---|---|
committer | Christian Heimes <christian@cheimes.de> | 2013-07-21 02:12:35 +0200 |
commit | ddf873f3236ddd20e30876020d8c446d69e64b7a (patch) | |
tree | e01e67693495c0d97283d6333a83e21c0536e4b6 /Python/traceback.c | |
parent | 5a1407a1764c76287e71f31f860b66e65d228703 (diff) | |
download | cpython-ddf873f3236ddd20e30876020d8c446d69e64b7a.tar.gz |
Check return value of lseek() in _Py_DisplaySourceLine().
Also use portable SEEK_SET instead of 0.
CID 1040639
Diffstat (limited to 'Python/traceback.c')
-rw-r--r-- | Python/traceback.c | 8 |
1 files changed, 7 insertions, 1 deletions
diff --git a/Python/traceback.c b/Python/traceback.c index c37aab0a9c..1f611ba1d5 100644 --- a/Python/traceback.c +++ b/Python/traceback.c @@ -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); |