[Python-checkins] cpython (3.3): Check return value of lseek() in _Py_DisplaySourceLine().

christian.heimes python-checkins at python.org
Sun Jul 21 02:12:53 CEST 2013


http://hg.python.org/cpython/rev/8fdb83492a58
changeset:   84757:8fdb83492a58
branch:      3.3
parent:      84755:15ac20ee5b70
user:        Christian Heimes <christian at cheimes.de>
date:        Sun Jul 21 02:12:35 2013 +0200
summary:
  Check return value of lseek() in _Py_DisplaySourceLine().
Also use portable SEEK_SET instead of 0.
CID 1040639

files:
  Python/traceback.c |  8 +++++++-
  1 files changed, 7 insertions(+), 1 deletions(-)


diff --git a/Python/traceback.c b/Python/traceback.c
--- a/Python/traceback.c
+++ b/Python/traceback.c
@@ -262,7 +262,13 @@
     }
     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);

-- 
Repository URL: http://hg.python.org/cpython


More information about the Python-checkins mailing list