]> granicus.if.org Git - python/commitdiff
fix #3653 Python could segfault if invalid values were passed to sys.excepthook
authorBenjamin Peterson <benjamin@python.org>
Sat, 23 Aug 2008 20:08:07 +0000 (20:08 +0000)
committerBenjamin Peterson <benjamin@python.org>
Sat, 23 Aug 2008 20:08:07 +0000 (20:08 +0000)
Author: Daniel Diniz
Reviewer: Georg Brandl

Python/pythonrun.c

index a1777bd5b2ed39a0f8b048e60e2707ee6a3a711e..1ee062fe6fa7b5675f778eed66a8104e9917ee57 100644 (file)
@@ -1300,6 +1300,13 @@ print_exception(PyObject *f, PyObject *value)
        int err = 0;
        PyObject *type, *tb;
 
+       if (!PyExceptionInstance_Check(value)) {
+               PyFile_WriteString("TypeError: print_exception(): Exception expected for value, ", f);
+               PyFile_WriteString(Py_TYPE(value)->tp_name, f);
+               PyFile_WriteString(" found\n", f);
+               return;
+       }
+
        Py_INCREF(value);
        fflush(stdout);
        type = (PyObject *) Py_TYPE(value);