[Python-checkins] cpython (3.2): check to make sure the attribute is a string (#14334)
benjamin.peterson
python-checkins at python.org
Fri Mar 16 15:36:59 CET 2012
http://hg.python.org/cpython/rev/b7bad204b34f
changeset: 75737:b7bad204b34f
branch: 3.2
parent: 75731:172630a3e6d8
user: Benjamin Peterson <benjamin at python.org>
date: Fri Mar 16 09:32:59 2012 -0500
summary:
check to make sure the attribute is a string (#14334)
files:
Lib/test/test_descr.py | 3 +++
Misc/NEWS | 3 +++
Objects/typeobject.c | 7 +++++++
3 files changed, 13 insertions(+), 0 deletions(-)
diff --git a/Lib/test/test_descr.py b/Lib/test/test_descr.py
--- a/Lib/test/test_descr.py
+++ b/Lib/test/test_descr.py
@@ -4393,6 +4393,9 @@
self.assertRaises(AttributeError, getattr, EvilGetattribute(), "attr")
+ def test_type___getattribute__(self):
+ self.assertRaises(TypeError, type.__getattribute__, list, type)
+
def test_abstractmethods(self):
# type pretends not to have __abstractmethods__.
self.assertRaises(AttributeError, getattr, type, "__abstractmethods__")
diff --git a/Misc/NEWS b/Misc/NEWS
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -10,6 +10,9 @@
Core and Builtins
-----------------
+- Issue #14334: Prevent in a segfault in type.__getattribute__ when it was not
+ passed strings.
+
- Issue #1469629: Allow cycles through an object's __dict__ slot to be
collected. (For example if ``x.__dict__ is x``).
diff --git a/Objects/typeobject.c b/Objects/typeobject.c
--- a/Objects/typeobject.c
+++ b/Objects/typeobject.c
@@ -2462,6 +2462,13 @@
PyObject *meta_attribute, *attribute;
descrgetfunc meta_get;
+ if (!PyUnicode_Check(name)) {
+ PyErr_Format(PyExc_TypeError,
+ "attribute name must be string, not '%.200s'",
+ name->ob_type->tp_name);
+ return NULL;
+ }
+
/* Initialize this type (we'll assume the metatype is initialized) */
if (type->tp_dict == NULL) {
if (PyType_Ready(type) < 0)
--
Repository URL: http://hg.python.org/cpython
More information about the Python-checkins
mailing list