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

Skip to content

Commit 90195e2

Browse files
committed
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.
1 parent 3b5de4d commit 90195e2

1 file changed

Lines changed: 4 additions & 2 deletions

File tree

Objects/object.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1362,7 +1362,8 @@ PyObject_GenericGetAttr(PyObject *obj, PyObject *name)
13621362
}
13631363

13641364
f = NULL;
1365-
if (descr != NULL) {
1365+
if (descr != NULL &&
1366+
PyType_HasFeature(descr->ob_type, Py_TPFLAGS_HAVE_CLASS)) {
13661367
f = descr->ob_type->tp_descr_get;
13671368
if (f != NULL && PyDescr_IsData(descr)) {
13681369
res = f(descr, obj, (PyObject *)obj->ob_type);
@@ -1454,7 +1455,8 @@ PyObject_GenericSetAttr(PyObject *obj, PyObject *name, PyObject *value)
14541455

14551456
descr = _PyType_Lookup(tp, name);
14561457
f = NULL;
1457-
if (descr != NULL) {
1458+
if (descr != NULL &&
1459+
PyType_HasFeature(descr->ob_type, Py_TPFLAGS_HAVE_CLASS)) {
14581460
f = descr->ob_type->tp_descr_set;
14591461
if (f != NULL && PyDescr_IsData(descr)) {
14601462
res = f(descr, obj, value);

0 commit comments

Comments
 (0)