summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBenjamin Peterson <benjamin@python.org>2012-03-16 14:32:59 (GMT)
committerBenjamin Peterson <benjamin@python.org>2012-03-16 14:32:59 (GMT)
commit16d84ac355c532a1e7d25cf75e0b577923de2856 (patch)
tree975ca5f98cf91f599673cf4a9e7477d11667b989
parent3fb05a90cefe29bad82c87336fa32de36e6add3d (diff)
downloadcpython-16d84ac355c532a1e7d25cf75e0b577923de2856.zip
cpython-16d84ac355c532a1e7d25cf75e0b577923de2856.tar.gz
cpython-16d84ac355c532a1e7d25cf75e0b577923de2856.tar.bz2
check to make sure the attribute is a string (#14334)
-rw-r--r--Lib/test/test_descr.py3
-rw-r--r--Misc/NEWS3
-rw-r--r--Objects/typeobject.c7
3 files changed, 13 insertions, 0 deletions
diff --git a/Lib/test/test_descr.py b/Lib/test/test_descr.py
index 4aeb77f..141d791 100644
--- a/Lib/test/test_descr.py
+++ b/Lib/test/test_descr.py
@@ -4393,6 +4393,9 @@ order (MRO) for bases """
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
index 772f78e..6659aad 100644
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -10,6 +10,9 @@ What's New in Python 3.2.4
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
index e006694..f0c787f 100644
--- a/Objects/typeobject.c
+++ b/Objects/typeobject.c
@@ -2462,6 +2462,13 @@ type_getattro(PyTypeObject *type, PyObject *name)
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)