changeset: 101931:c071da010053 branch: 2.7 parent: 101923:7dfee711da42 user: Serhiy Storchaka date: Sun Jun 12 10:06:32 2016 +0300 files: Misc/NEWS Modules/_elementtree.c description: Issue #25455: Fixed a crash in repr of cElementTree.Element with recursive tag. diff -r 7dfee711da42 -r c071da010053 Misc/NEWS --- a/Misc/NEWS Sun Jun 12 06:14:03 2016 +0000 +++ b/Misc/NEWS Sun Jun 12 10:06:32 2016 +0300 @@ -13,6 +13,8 @@ Library ------- +- Issue #25455: Fixed a crash in repr of cElementTree.Element with recursive tag. + Documentation ------------- diff -r 7dfee711da42 -r c071da010053 Modules/_elementtree.c --- a/Modules/_elementtree.c Sun Jun 12 06:14:03 2016 +0000 +++ b/Modules/_elementtree.c Sun Jun 12 10:06:32 2016 +0300 @@ -1222,18 +1222,28 @@ static PyObject* element_repr(ElementObject* self) { - PyObject *repr, *tag; - - tag = PyObject_Repr(self->tag); - if (!tag) - return NULL; - - repr = PyString_FromFormat("", - PyString_AS_STRING(tag), self); - - Py_DECREF(tag); - - return repr; + int status; + + if (self->tag == NULL) + return PyUnicode_FromFormat("", self); + + status = Py_ReprEnter((PyObject *)self); + if (status == 0) { + PyObject *repr, *tag; + tag = PyObject_Repr(self->tag); + if (!tag) + return NULL; + + repr = PyString_FromFormat("", + PyString_AS_STRING(tag), self); + Py_DECREF(tag); + return repr; + } + if (status > 0) + PyErr_Format(PyExc_RuntimeError, + "reentrant call inside %s.__repr__", + Py_TYPE(self)->tp_name); + return NULL; } static PyObject*