check to make sure the attribute is a string (#14334)
diff --git a/Lib/test/test_descr.py b/Lib/test/test_descr.py
index 4050524..28dfbff 100644
--- a/Lib/test/test_descr.py
+++ b/Lib/test/test_descr.py
@@ -4554,6 +4554,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
index b8edcaa..40c88d9 100644
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -9,6 +9,9 @@
Core and Builtins
-----------------
+- Issue #14334: Prevent in a segfault in type.__getattribute__ when it was not
+ passed strings.
+
- Issue #14161: fix the __repr__ of file objects to escape the file name.
- Issue #1469629: Allow cycles through an object's __dict__ slot to be
diff --git a/Objects/typeobject.c b/Objects/typeobject.c
index ce1d42b..877bcb7 100644
--- a/Objects/typeobject.c
+++ b/Objects/typeobject.c
@@ -2530,6 +2530,13 @@
PyObject *meta_attribute, *attribute;
descrgetfunc meta_get;
+ if (!PyString_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)