Issue #25455: Fixed a crash in repr of ElementTree.Element with recursive tag.

This commit is contained in:
Serhiy Storchaka 2016-06-12 09:47:20 +03:00
commit f0ee5ccd19
3 changed files with 25 additions and 4 deletions

View file

@ -1610,10 +1610,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]