summaryrefslogtreecommitdiffstats
path: root/Objects
diff options
context:
space:
mode:
authorMichael W. Hudson <mwh@python.net>2003-08-15 13:07:47 (GMT)
committerMichael W. Hudson <mwh@python.net>2003-08-15 13:07:47 (GMT)
commitb2c7de46673e654aec8d2c9b000cce2b071a5093 (patch)
tree9f70390e3c74935ed99f0fa1090435d82bf5d47c /Objects
parentf02bcee095bf0343b9871fd28cf2d580337c599a (diff)
downloadcpython-b2c7de46673e654aec8d2c9b000cce2b071a5093.zip
cpython-b2c7de46673e654aec8d2c9b000cce2b071a5093.tar.gz
cpython-b2c7de46673e654aec8d2c9b000cce2b071a5093.tar.bz2
Fix for
[ 784825 ] fix obscure crash in descriptor handling Should be applied to release23-maint and in all likelyhood release22-maint, too. Certainly doesn't apply to release21-maint.
Diffstat (limited to 'Objects')
-rw-r--r--Objects/object.c7
-rw-r--r--Objects/typeobject.c15
2 files changed, 17 insertions, 5 deletions
diff --git a/Objects/object.c b/Objects/object.c
index 93057c0..8c4bd0e 100644
--- a/Objects/object.c
+++ b/Objects/object.c
@@ -1412,12 +1412,15 @@ PyObject_GenericGetAttr(PyObject *obj, PyObject *name)
}
}
+ Py_XINCREF(descr);
+
f = NULL;
if (descr != NULL &&
PyType_HasFeature(descr->ob_type, Py_TPFLAGS_HAVE_CLASS)) {
f = descr->ob_type->tp_descr_get;
if (f != NULL && PyDescr_IsData(descr)) {
res = f(descr, obj, (PyObject *)obj->ob_type);
+ Py_DECREF(descr);
goto done;
}
}
@@ -1445,6 +1448,7 @@ PyObject_GenericGetAttr(PyObject *obj, PyObject *name)
res = PyDict_GetItem(dict, name);
if (res != NULL) {
Py_INCREF(res);
+ Py_XDECREF(descr);
goto done;
}
}
@@ -1452,12 +1456,13 @@ PyObject_GenericGetAttr(PyObject *obj, PyObject *name)
if (f != NULL) {
res = f(descr, obj, (PyObject *)obj->ob_type);
+ Py_DECREF(descr);
goto done;
}
if (descr != NULL) {
- Py_INCREF(descr);
res = descr;
+ /* descr was already increfed above */
goto done;
}
diff --git a/Objects/typeobject.c b/Objects/typeobject.c
index 5c0f73a..af255f1 100644
--- a/Objects/typeobject.c
+++ b/Objects/typeobject.c
@@ -2010,6 +2010,7 @@ type_getattro(PyTypeObject *type, PyObject *name)
return meta_get(meta_attribute, (PyObject *)type,
(PyObject *)metatype);
}
+ Py_INCREF(meta_attribute);
}
/* No data descriptor found on metatype. Look in tp_dict of this
@@ -2018,6 +2019,9 @@ type_getattro(PyTypeObject *type, PyObject *name)
if (attribute != NULL) {
/* Implement descriptor functionality, if any */
descrgetfunc local_get = attribute->ob_type->tp_descr_get;
+
+ Py_XDECREF(meta_attribute);
+
if (local_get != NULL) {
/* NULL 2nd argument indicates the descriptor was
* found on the target object itself (or a base) */
@@ -2031,13 +2035,16 @@ type_getattro(PyTypeObject *type, PyObject *name)
/* No attribute found in local __dict__ (or bases): use the
* descriptor from the metatype, if any */
- if (meta_get != NULL)
- return meta_get(meta_attribute, (PyObject *)type,
- (PyObject *)metatype);
+ if (meta_get != NULL) {
+ PyObject *res;
+ res = meta_get(meta_attribute, (PyObject *)type,
+ (PyObject *)metatype);
+ Py_DECREF(meta_attribute);
+ return res;
+ }
/* If an ordinary attribute was found on the metatype, return it now */
if (meta_attribute != NULL) {
- Py_INCREF(meta_attribute);
return meta_attribute;
}