diff Python/errors.c @ 43276:3bc3f12cae28 legacy-trunk

Fix a crasher where Python code managed to infinitely recurse in C code without ever going back out to Python code in PyObject_Call(). Required introducing a static RuntimeError instance so that normalizing an exception there is no reliance on a recursive call that would put the exception system over the recursion check itself.
author Brett Cannon <bcannon@gmail.com>
date Fri, 07 Sep 2007 04:18:30 +0000
parents c83acfb1a632
children 0cbe94bea2c7
line wrap: on
line diff
--- a/Python/errors.c	Fri Sep 07 03:17:50 2007 +0000
+++ b/Python/errors.c	Fri Sep 07 04:18:30 2007 +0000
@@ -132,6 +132,7 @@
 	PyObject *value = *val;
 	PyObject *inclass = NULL;
 	PyObject *initial_tb = NULL;
+	PyThreadState *tstate = NULL;
 
 	if (type == NULL) {
 		/* There was no exception, so nothing to do. */
@@ -207,7 +208,14 @@
 			Py_DECREF(initial_tb);
 	}
 	/* normalize recursively */
+	tstate = PyThreadState_GET();
+	if (++tstate->recursion_depth > Py_GetRecursionLimit()) {
+	    --tstate->recursion_depth;
+	    PyErr_SetObject(PyExc_RuntimeError, PyExc_RecursionErrorInst);
+	    return;
+	}
 	PyErr_NormalizeException(exc, val, tb);
+	--tstate->recursion_depth;
 }