From: Brett Cannon Date: Tue, 13 Jun 2006 21:50:24 +0000 (+0000) Subject: Classic class that defined ``def __coerce__(self, other): return other, self`` X-Git-Tag: v2.4.4c1~180 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=df43ce33fb0a1720c986d82cafb0be8cf60ba844;p=thirdparty%2FPython%2Fcpython.git Classic class that defined ``def __coerce__(self, other): return other, self`` would infinitely recourse and segfault the interpreter. Now a recursion check occurs after a coercion. Backport of fix for bug #992017. --- diff --git a/Misc/NEWS b/Misc/NEWS index f83d112fe62b..005255fdaa7c 100644 --- a/Misc/NEWS +++ b/Misc/NEWS @@ -12,6 +12,9 @@ What's New in Python 2.4.4c1? Core and builtins ----------------- +- Bug #992017: A classic class that defined a __coerce__() method that returned + its arguments swapped would infinitely recurse and segfault the interpreter. + - Bug #532646: The object set to the __call__ attribute has its own __call__ attribute checked; this continues until the attribute can no longer be found or segfaulting. Recursion limit is now followed. diff --git a/Objects/classobject.c b/Objects/classobject.c index 187f8d0648c1..bbd4c6d8f53c 100644 --- a/Objects/classobject.c +++ b/Objects/classobject.c @@ -1428,10 +1428,13 @@ half_binop(PyObject *v, PyObject *w, char *opname, binaryfunc thisfunc, * argument */ result = generic_binary_op(v1, w, opname); } else { + if (Py_EnterRecursiveCall(" after coercion")) + return NULL; if (swapped) result = (thisfunc)(w, v1); else result = (thisfunc)(v1, w); + Py_LeaveRecursiveCall(); } Py_DECREF(coerced); return result;