Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit de39454

Browse files
committed
merge 3.2 (#14334)
2 parents 6e33525 + 16d84ac commit de39454

3 files changed

Lines changed: 13 additions & 0 deletions

File tree

Lib/test/test_descr.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4400,6 +4400,9 @@ def __getattribute__(self, name):
44004400

44014401
self.assertRaises(AttributeError, getattr, EvilGetattribute(), "attr")
44024402

4403+
def test_type___getattribute__(self):
4404+
self.assertRaises(TypeError, type.__getattribute__, list, type)
4405+
44034406
def test_abstractmethods(self):
44044407
# type pretends not to have __abstractmethods__.
44054408
self.assertRaises(AttributeError, getattr, type, "__abstractmethods__")

Misc/NEWS

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,9 @@ Core and Builtins
1212

1313
- Give the ast.AST class a __dict__.
1414

15+
- Issue #14334: Prevent in a segfault in type.__getattribute__ when it was not
16+
passed strings.
17+
1518
- Issue #1469629: Allow cycles through an object's __dict__ slot to be
1619
collected. (For example if ``x.__dict__ is x``).
1720

Objects/typeobject.c

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2486,6 +2486,13 @@ type_getattro(PyTypeObject *type, PyObject *name)
24862486
PyObject *meta_attribute, *attribute;
24872487
descrgetfunc meta_get;
24882488

2489+
if (!PyUnicode_Check(name)) {
2490+
PyErr_Format(PyExc_TypeError,
2491+
"attribute name must be string, not '%.200s'",
2492+
name->ob_type->tp_name);
2493+
return NULL;
2494+
}
2495+
24892496
/* Initialize this type (we'll assume the metatype is initialized) */
24902497
if (type->tp_dict == NULL) {
24912498
if (PyType_Ready(type) < 0)

0 commit comments

Comments
 (0)