From: Benjamin Peterson Date: Mon, 20 May 2013 02:38:12 +0000 (-0700) Subject: add missing NULL check (closes #18019) X-Git-Tag: v2.7.6rc1~386 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=b91ef008baf3f6954bf2849f7b5235f9d1a1f6d8;p=thirdparty%2FPython%2Fcpython.git add missing NULL check (closes #18019) --- diff --git a/Lib/test/test_dictviews.py b/Lib/test/test_dictviews.py index f90367660c54..b264ff2ba16b 100644 --- a/Lib/test/test_dictviews.py +++ b/Lib/test/test_dictviews.py @@ -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) + diff --git a/Misc/NEWS b/Misc/NEWS index efd7724a8e5d..cb7fd6006e3f 100644 --- 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 ------- diff --git a/Objects/dictobject.c b/Objects/dictobject.c index ba36b180cad2..39e703590103 100644 --- a/Objects/dictobject.c +++ b/Objects/dictobject.c @@ -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);