summaryrefslogtreecommitdiff
path: root/Python/errors.c
diff options
context:
space:
mode:
authorBrett Cannon <bcannon@gmail.com>2007-09-07 04:18:30 +0000
committerBrett Cannon <bcannon@gmail.com>2007-09-07 04:18:30 +0000
commit1e534b5425d836cb58a73d24f0be791d67bf3503 (patch)
tree1f9fc8b8802c5ba236c026fc6cbe785d7f9bf20b /Python/errors.c
parent68a6da99e6dc127d817143f74e98d665117f99c2 (diff)
downloadcpython-git-1e534b5425d836cb58a73d24f0be791d67bf3503.tar.gz
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.
Diffstat (limited to 'Python/errors.c')
-rw-r--r--Python/errors.c8
1 files changed, 8 insertions, 0 deletions
diff --git a/Python/errors.c b/Python/errors.c
index 3b8ea64f67..63acf33066 100644
--- a/Python/errors.c
+++ b/Python/errors.c
@@ -132,6 +132,7 @@ PyErr_NormalizeException(PyObject **exc, PyObject **val, PyObject **tb)
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 @@ finally:
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;
}