summaryrefslogtreecommitdiffstats
path: root/Python/traceback.c
diff options
context:
space:
mode:
authorChristian Heimes <christian@cheimes.de>2013-07-21 00:12:44 (GMT)
committerChristian Heimes <christian@cheimes.de>2013-07-21 00:12:44 (GMT)
commit02e8b53e6da8b89466b87eaf2f1f8ee027962cbe (patch)
treee5d924581e7b52a86340e7992a16e2c69f8d854c /Python/traceback.c
parent68959475705df9bae196e26c4d9ea82f2e2ca7ad (diff)
parent1f34729f42c0f386c5c95580ba736fd9758cf9a2 (diff)
downloadcpython-02e8b53e6da8b89466b87eaf2f1f8ee027962cbe.zip
cpython-02e8b53e6da8b89466b87eaf2f1f8ee027962cbe.tar.gz
cpython-02e8b53e6da8b89466b87eaf2f1f8ee027962cbe.tar.bz2
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.c8
1 files changed, 7 insertions, 1 deletions
diff --git a/Python/traceback.c b/Python/traceback.c
index 399a174..3101580 100644
--- a/Python/traceback.c
+++ b/Python/traceback.c
@@ -264,7 +264,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);