Kaydet (Commit) ea3912b0 authored tarafından Brett Cannon's avatar Brett Cannon

If a classic class defined a __coerce__() method that just returned its two

arguments in reverse, the interpreter would infinitely recourse trying to get a
coercion that worked.  So put in a recursion check after a coercion is made and
the next call to attempt to use the coerced values.

Fixes bug #992017 and closes crashers/coerce.py .
üst 64116f93
# http://python.org/sf/992017
class foo:
def __coerce__(self, other):
return other, self
if __name__ == '__main__':
foo()+1 # segfault: infinite recursion in C
...@@ -12,6 +12,9 @@ What's New in Python 2.5 beta 1? ...@@ -12,6 +12,9 @@ What's New in Python 2.5 beta 1?
Core and builtins 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.
- Fix the socket tests so they can be run concurrently. - Fix the socket tests so they can be run concurrently.
- Removed 5 integers from C frame objects (PyFrameObject). - Removed 5 integers from C frame objects (PyFrameObject).
......
...@@ -1368,10 +1368,13 @@ half_binop(PyObject *v, PyObject *w, char *opname, binaryfunc thisfunc, ...@@ -1368,10 +1368,13 @@ half_binop(PyObject *v, PyObject *w, char *opname, binaryfunc thisfunc,
* argument */ * argument */
result = generic_binary_op(v1, w, opname); result = generic_binary_op(v1, w, opname);
} else { } else {
if (Py_EnterRecursiveCall(" after coercion"))
return NULL;
if (swapped) if (swapped)
result = (thisfunc)(w, v1); result = (thisfunc)(w, v1);
else else
result = (thisfunc)(v1, w); result = (thisfunc)(v1, w);
Py_LeaveRecursiveCall();
} }
Py_DECREF(coerced); Py_DECREF(coerced);
return result; return result;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment