From df43ce33fb0a1720c986d82cafb0be8cf60ba844 Mon Sep 17 00:00:00 2001 From: Brett Cannon Date: Tue, 13 Jun 2006 21:50:24 +0000 Subject: [PATCH] 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. --- Misc/NEWS | 3 +++ Objects/classobject.c | 3 +++ 2 files changed, 6 insertions(+) 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; -- 2.47.3