From: Serhiy Storchaka Date: Sun, 12 Jun 2016 07:06:32 +0000 (+0300) Subject: Issue #25455: Fixed a crash in repr of cElementTree.Element with recursive tag. X-Git-Tag: v2.7.13rc1~295 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=1f7586eeb921d4b1116823b2aea752aaee1329ce;p=thirdparty%2FPython%2Fcpython.git Issue #25455: Fixed a crash in repr of cElementTree.Element with recursive tag. --- diff --git a/Misc/NEWS b/Misc/NEWS index 55f44bf69fdc..b7785e5e415e 100644 --- a/Misc/NEWS +++ b/Misc/NEWS @@ -13,6 +13,8 @@ Core and Builtins Library ------- +- Issue #25455: Fixed a crash in repr of cElementTree.Element with recursive tag. + Documentation ------------- diff --git a/Modules/_elementtree.c b/Modules/_elementtree.c index 6f628a5c1444..df97b5e698fd 100644 --- a/Modules/_elementtree.c +++ b/Modules/_elementtree.c @@ -1222,18 +1222,28 @@ element_remove(ElementObject* self, PyObject* args) static PyObject* element_repr(ElementObject* self) { - PyObject *repr, *tag; + int status; - tag = PyObject_Repr(self->tag); - if (!tag) - return NULL; + if (self->tag == NULL) + return PyUnicode_FromFormat("", self); - repr = PyString_FromFormat("", - PyString_AS_STRING(tag), self); - - Py_DECREF(tag); + status = Py_ReprEnter((PyObject *)self); + if (status == 0) { + PyObject *repr, *tag; + tag = PyObject_Repr(self->tag); + if (!tag) + return NULL; - return repr; + 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*