diff options
author | Serhiy Storchaka <storchaka@gmail.com> | 2016-06-12 06:43:55 (GMT) |
---|---|---|
committer | Serhiy Storchaka <storchaka@gmail.com> | 2016-06-12 06:43:55 (GMT) |
commit | 9062c261a4f9268f4621548ec205c80411f75b6e (patch) | |
tree | e6f41d63259f2c1bfa3bac2ebbe3a13f20047d3b /Modules | |
parent | 3c317e76a2fe78896b546e08fa753075463e7d41 (diff) | |
download | cpython-9062c261a4f9268f4621548ec205c80411f75b6e.zip cpython-9062c261a4f9268f4621548ec205c80411f75b6e.tar.gz cpython-9062c261a4f9268f4621548ec205c80411f75b6e.tar.bz2 |
Issue #25455: Fixed a crash in repr of ElementTree.Element with recursive tag.
Diffstat (limited to 'Modules')
-rw-r--r-- | Modules/_elementtree.c | 19 |
1 files changed, 16 insertions, 3 deletions
diff --git a/Modules/_elementtree.c b/Modules/_elementtree.c index 0f1d6a1..85ffca2 100644 --- a/Modules/_elementtree.c +++ b/Modules/_elementtree.c @@ -1582,10 +1582,23 @@ _elementtree_Element_remove_impl(ElementObject *self, PyObject *subelement) static PyObject* element_repr(ElementObject* self) { - if (self->tag) - return PyUnicode_FromFormat("<Element %R at %p>", self->tag, self); - else + int status; + + if (self->tag == NULL) return PyUnicode_FromFormat("<Element at %p>", self); + + status = Py_ReprEnter((PyObject *)self); + if (status == 0) { + PyObject *res; + res = PyUnicode_FromFormat("<Element %R at %p>", self->tag, self); + Py_ReprLeave((PyObject *)self); + return res; + } + if (status > 0) + PyErr_Format(PyExc_RuntimeError, + "reentrant call inside %s.__repr__", + Py_TYPE(self)->tp_name); + return NULL; } /*[clinic input] |