]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
Check return value of lseek() in _Py_DisplaySourceLine().
authorChristian Heimes <christian@cheimes.de>
Sun, 21 Jul 2013 00:12:35 +0000 (02:12 +0200)
committerChristian Heimes <christian@cheimes.de>
Sun, 21 Jul 2013 00:12:35 +0000 (02:12 +0200)
Also use portable SEEK_SET instead of 0.
CID 1040639

Python/traceback.c

index c37aab0a9c11bb968b91a1f22b3d15892cba236b..1f611ba1d5152c6fd753280148b9eb28c196db38 100644 (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);