diff Python/traceback.c @ 84757:8fdb83492a58 3.3

Check return value of lseek() in _Py_DisplaySourceLine(). Also use portable SEEK_SET instead of 0. CID 1040639
author Christian Heimes <christian@cheimes.de>
date Sun, 21 Jul 2013 02:12:35 +0200
parents 82e9a9f8be3c
children 34ca4dd47c54 228180598aab
line wrap: on
line diff
--- a/Python/traceback.c	Sun Jul 21 02:04:35 2013 +0200
+++ b/Python/traceback.c	Sun Jul 21 02:12:35 2013 +0200
@@ -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);