From 5afa03a72ee6d27e742dc0ebc06a0630e1b37fe9 Mon Sep 17 00:00:00 2001 From: Benjamin Peterson Date: Fri, 15 Jul 2011 14:09:26 -0500 Subject: catch nasty exception classes with __new__ that doesn't return a exception (closes #11627) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Patch from Andreas Stührk. --- Python/ceval.c | 7 +++++++ 1 file changed, 7 insertions(+) (limited to 'Python/ceval.c') diff --git a/Python/ceval.c b/Python/ceval.c index 5c3bb832cda..f0ea7c90dca 100644 --- a/Python/ceval.c +++ b/Python/ceval.c @@ -3413,6 +3413,13 @@ do_raise(PyObject *exc, PyObject *cause) value = PyObject_CallObject(exc, NULL); if (value == NULL) goto raise_error; + if (!PyExceptionInstance_Check(value)) { + PyErr_Format(PyExc_TypeError, + "calling %R should have returned an instance of " + "BaseException, not %R", + type, Py_TYPE(value)); + goto raise_error; + } } else if (PyExceptionInstance_Check(exc)) { value = exc; -- cgit v1.2.3