comparison Python/errors.c @ 73880:57de1ad15c54 2.7

Issue #13546: Fixed an overflow issue that could crash the intepreter when calling sys.setrecursionlimit((1<<31)-1). 2.7 only.
author Amaury Forgeot d'Arc <amauryfa@gmail.com>
date Wed, 07 Dec 2011 21:46:48 +0100
parents b36cb4602e21
children
comparison
equal deleted inserted replaced
73872:5910c385fab6 73880:57de1ad15c54
109 int res = 0, reclimit; 109 int res = 0, reclimit;
110 PyObject *exception, *value, *tb; 110 PyObject *exception, *value, *tb;
111 PyErr_Fetch(&exception, &value, &tb); 111 PyErr_Fetch(&exception, &value, &tb);
112 /* Temporarily bump the recursion limit, so that in the most 112 /* Temporarily bump the recursion limit, so that in the most
113 common case PyObject_IsSubclass will not raise a recursion 113 common case PyObject_IsSubclass will not raise a recursion
114 error we have to ignore anyway. */ 114 error we have to ignore anyway. Don't do it when the limit
115 is already insanely high, to avoid overflow */
115 reclimit = Py_GetRecursionLimit(); 116 reclimit = Py_GetRecursionLimit();
116 Py_SetRecursionLimit(reclimit + 5); 117 if (reclimit < (1 << 30))
118 Py_SetRecursionLimit(reclimit + 5);
117 res = PyObject_IsSubclass(err, exc); 119 res = PyObject_IsSubclass(err, exc);
118 Py_SetRecursionLimit(reclimit); 120 Py_SetRecursionLimit(reclimit);
119 /* This function must not fail, so print the error here */ 121 /* This function must not fail, so print the error here */
120 if (res == -1) { 122 if (res == -1) {
121 PyErr_WriteUnraisable(err); 123 PyErr_WriteUnraisable(err);