diff options
author | Guido van Rossum <guido@python.org> | 2008-04-10 22:43:58 (GMT) |
---|---|---|
committer | Guido van Rossum <guido@python.org> | 2008-04-10 22:43:58 (GMT) |
commit | aa975432d4456c69e1b1fd2a335f01261175f798 (patch) | |
tree | 55a0db3a38cee1d9b440c9e878906ed82fcea3ca /Objects/object.c | |
parent | a6add69a63385da3e8abf34023b671137479bf5a (diff) | |
download | cpython-aa975432d4456c69e1b1fd2a335f01261175f798.zip cpython-aa975432d4456c69e1b1fd2a335f01261175f798.tar.gz cpython-aa975432d4456c69e1b1fd2a335f01261175f798.tar.bz2 |
- Issue #1686386: Tuple's tp_repr did not take into account the possibility of
having a self-referential tuple, which is possible from C code. Nor did
object's tp_str consider that a type's tp_str could do something that could
lead to an inifinite recursion. Py_ReprEnter() and Py_EnterRecursiveCall(),
respectively, fixed the issues. (Backport of r58288 from trunk to 2.5.)
Diffstat (limited to 'Objects/object.c')
-rw-r--r-- | Objects/object.c | 6 |
1 files changed, 5 insertions, 1 deletions
diff --git a/Objects/object.c b/Objects/object.c index 71e5641..af7be01 100644 --- a/Objects/object.c +++ b/Objects/object.c @@ -403,7 +403,12 @@ _PyObject_Str(PyObject *v) if (v->ob_type->tp_str == NULL) return PyObject_Repr(v); + /* It is possible for a type to have a tp_str representation that loops + infinitely. */ + if (Py_EnterRecursiveCall(" while getting the str of an object")) + return NULL; res = (*v->ob_type->tp_str)(v); + Py_LeaveRecursiveCall(); if (res == NULL) return NULL; type_ok = PyString_Check(res); @@ -2141,4 +2146,3 @@ _PyTrash_destroy_chain(void) #ifdef __cplusplus } #endif - |