PyObject_Generic{Get,Set}Attr:

Don't access tp_descr_{get,set} of a descriptor without checking the
flag bits of the descriptor's type.  While we know that the main type
(the type of the object whose attribute is being accessed) has all the
right flag bits (or else PyObject_Generic{Get,Set}Attr wouldn't be
called), we don't know that for its class attributes!

Will backport to 2.2.
This commit is contained in:
Guido van Rossum 2003-02-19 03:19:29 +00:00
parent 3b5de4db92
commit 90195e2616

View File

@ -1362,7 +1362,8 @@ PyObject_GenericGetAttr(PyObject *obj, PyObject *name)
} }
f = NULL; f = NULL;
if (descr != NULL) { if (descr != NULL &&
PyType_HasFeature(descr->ob_type, Py_TPFLAGS_HAVE_CLASS)) {
f = descr->ob_type->tp_descr_get; f = descr->ob_type->tp_descr_get;
if (f != NULL && PyDescr_IsData(descr)) { if (f != NULL && PyDescr_IsData(descr)) {
res = f(descr, obj, (PyObject *)obj->ob_type); res = f(descr, obj, (PyObject *)obj->ob_type);
@ -1454,7 +1455,8 @@ PyObject_GenericSetAttr(PyObject *obj, PyObject *name, PyObject *value)
descr = _PyType_Lookup(tp, name); descr = _PyType_Lookup(tp, name);
f = NULL; f = NULL;
if (descr != NULL) { if (descr != NULL &&
PyType_HasFeature(descr->ob_type, Py_TPFLAGS_HAVE_CLASS)) {
f = descr->ob_type->tp_descr_set; f = descr->ob_type->tp_descr_set;
if (f != NULL && PyDescr_IsData(descr)) { if (f != NULL && PyDescr_IsData(descr)) {
res = f(descr, obj, value); res = f(descr, obj, value);