]> granicus.if.org Git - python/commitdiff
Issue #25455: Fixed a crash in repr of cElementTree.Element with recursive tag.
authorSerhiy Storchaka <storchaka@gmail.com>
Sun, 12 Jun 2016 07:06:32 +0000 (10:06 +0300)
committerSerhiy Storchaka <storchaka@gmail.com>
Sun, 12 Jun 2016 07:06:32 +0000 (10:06 +0300)
Misc/NEWS
Modules/_elementtree.c

index 55f44bf69fdc79eaa6933de4e0ded437f850e284..b7785e5e415e3d38016459c8d19075cfde91a3e2 100644 (file)
--- 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
 -------------
 
index 6f628a5c1444d4ea3e775f10a83c8b4d417050c3..df97b5e698fd4d3dfd2bf2ca22d008fcdee43f71 100644 (file)
@@ -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("<Element at %p>", self);
 
-    repr = PyString_FromFormat("<Element %s at %p>",
-                               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("<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*