]> granicus.if.org Git - python/commitdiff
check to make sure the attribute is a string (#14334)
authorBenjamin Peterson <benjamin@python.org>
Fri, 16 Mar 2012 14:32:59 +0000 (09:32 -0500)
committerBenjamin Peterson <benjamin@python.org>
Fri, 16 Mar 2012 14:32:59 +0000 (09:32 -0500)
Lib/test/test_descr.py
Misc/NEWS
Objects/typeobject.c

index 4aeb77fd0f202a2bb80c42e8907c710adca39725..141d7918ddf712796d2d92f434f4dd8dd7f0f875 100644 (file)
@@ -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__")
index 772f78e97ddbbdc2753e641fc5260638bd38b11f..6659aadcfcccc40449cffba90741aad8ed794e2c 100644 (file)
--- 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``).
 
index e00669480590a5f89cd1f2379deb2a70b80d7561..f0c787fa2a54cc4df96954d719228c8a7ee9be10 100644 (file)
@@ -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)