[Python-checkins] cpython (2.7): Issue #25455: Fixed a crash in repr of cElementTree.Element with recursive tag.
serhiy.storchaka
python-checkins at python.org
Sun Jun 12 04:57:43 EDT 2016
https://hg.python.org/cpython/rev/c071da010053
changeset: 101931:c071da010053
branch: 2.7
parent: 101923:7dfee711da42
user: Serhiy Storchaka <storchaka at gmail.com>
date: Sun Jun 12 10:06:32 2016 +0300
summary:
Issue #25455: Fixed a crash in repr of cElementTree.Element with recursive tag.
files:
Misc/NEWS | 2 +
Modules/_elementtree.c | 34 +++++++++++++++++++----------
2 files changed, 24 insertions(+), 12 deletions(-)
diff --git a/Misc/NEWS b/Misc/NEWS
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -13,6 +13,8 @@
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
--- a/Modules/_elementtree.c
+++ b/Modules/_elementtree.c
@@ -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("<Element %s at %p>",
- PyString_AS_STRING(tag), self);
-
- Py_DECREF(tag);
-
- return repr;
+ int status;
+
+ if (self->tag == NULL)
+ return PyUnicode_FromFormat("<Element at %p>", self);
+
+ status = Py_ReprEnter((PyObject *)self);
+ if (status == 0) {
+ PyObject *repr, *tag;
+ tag = PyObject_Repr(self->tag);
+ if (!tag)
+ return NULL;
+
+ repr = PyString_FromFormat("<Element %s at %p>",
+ 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*
--
Repository URL: https://hg.python.org/cpython
More information about the Python-checkins
mailing list