diff Python/pythonrun.c @ 48839:587cd4f66c2d

fix #3653 Python could segfault if invalid values were passed to sys.excepthook Author: Daniel Diniz Reviewer: Georg Brandl
author Benjamin Peterson <benjamin@python.org>
date Sat, 23 Aug 2008 20:08:07 +0000
parents 85b67fb5672b
children 4db1f5098175
line wrap: on
line diff
--- a/Python/pythonrun.c	Sat Aug 23 15:21:08 2008 +0000
+++ b/Python/pythonrun.c	Sat Aug 23 20:08:07 2008 +0000
@@ -1300,6 +1300,13 @@
 	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);