mirror of
https://github.com/python/cpython.git
synced 2025-11-27 05:44:16 +00:00
check to make sure the attribute is a string (#14334)
This commit is contained in:
parent
51a65c9161
commit
6e7832b04c
3 changed files with 13 additions and 0 deletions
|
|
@ -4554,6 +4554,9 @@ order (MRO) for bases """
|
||||||
|
|
||||||
self.assertRaises(AttributeError, getattr, EvilGetattribute(), "attr")
|
self.assertRaises(AttributeError, getattr, EvilGetattribute(), "attr")
|
||||||
|
|
||||||
|
def test_type___getattribute__(self):
|
||||||
|
self.assertRaises(TypeError, type.__getattribute__, list, type)
|
||||||
|
|
||||||
def test_abstractmethods(self):
|
def test_abstractmethods(self):
|
||||||
# type pretends not to have __abstractmethods__.
|
# type pretends not to have __abstractmethods__.
|
||||||
self.assertRaises(AttributeError, getattr, type, "__abstractmethods__")
|
self.assertRaises(AttributeError, getattr, type, "__abstractmethods__")
|
||||||
|
|
|
||||||
|
|
@ -9,6 +9,9 @@ What's New in Python 2.7.4
|
||||||
Core and Builtins
|
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 #14161: fix the __repr__ of file objects to escape the file name.
|
||||||
|
|
||||||
- Issue #1469629: Allow cycles through an object's __dict__ slot to be
|
- Issue #1469629: Allow cycles through an object's __dict__ slot to be
|
||||||
|
|
|
||||||
|
|
@ -2530,6 +2530,13 @@ type_getattro(PyTypeObject *type, PyObject *name)
|
||||||
PyObject *meta_attribute, *attribute;
|
PyObject *meta_attribute, *attribute;
|
||||||
descrgetfunc meta_get;
|
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) */
|
/* Initialize this type (we'll assume the metatype is initialized) */
|
||||||
if (type->tp_dict == NULL) {
|
if (type->tp_dict == NULL) {
|
||||||
if (PyType_Ready(type) < 0)
|
if (PyType_Ready(type) < 0)
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue