]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
add missing NULL check (closes #18019)
authorBenjamin Peterson <benjamin@python.org>
Mon, 20 May 2013 02:38:12 +0000 (19:38 -0700)
committerBenjamin Peterson <benjamin@python.org>
Mon, 20 May 2013 02:38:12 +0000 (19:38 -0700)
Lib/test/test_dictviews.py
Misc/NEWS
Objects/dictobject.c

index f90367660c54b83e4d00e0ac510a6740a9dd1e80..b264ff2ba16b5a2da39d4cb535ae9bb0295b4cf8 100644 (file)
@@ -144,6 +144,11 @@ class DictSetTest(unittest.TestCase):
         self.assertEqual(d1.viewitems() ^ d3.viewitems(),
                          {('a', 1), ('b', 2), ('d', 4), ('e', 5)})
 
+    def test_recursive_repr(self):
+        d = {}
+        d[42] = d.viewvalues()
+        self.assertRaises(RuntimeError, repr, d)
+
 
 
 
index efd7724a8e5dae0e82c9ba2b653312ca3eb5996e..cb7fd6006e3f2bbb5d3cfe525386167e5a1fa937 100644 (file)
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -9,6 +9,9 @@ What's New in Python 2.7.6?
 Core and Builtins
 -----------------
 
+- Issue #18019: Fix crash in the repr of dictionaries containing their own
+  views.
+
 Library
 -------
 
index ba36b180cad23a48fd9671ba268961e57a334524..39e7035901033985706cffb243f5440d77fb3645 100644 (file)
@@ -2919,6 +2919,10 @@ dictview_repr(dictviewobject *dv)
         return NULL;
 
     seq_str = PyObject_Repr(seq);
+    if (seq_str == NULL) {
+        Py_DECREF(seq);
+        return NULL;
+    }
     result = PyString_FromFormat("%s(%s)", Py_TYPE(dv)->tp_name,
                                  PyString_AS_STRING(seq_str));
     Py_DECREF(seq_str);