summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBenjamin Peterson <benjamin@python.org>2008-11-17 23:27:02 (GMT)
committerBenjamin Peterson <benjamin@python.org>2008-11-17 23:27:02 (GMT)
commit38ce9c294b00a615f78b8f03ff2cc60fdf0fc7c2 (patch)
tree6fc160570046ddf3aa25006412e44ae14aa508b7
parent3a87f93c42d0ca5b3af56076ba023eebe33cf29e (diff)
downloadcpython-38ce9c294b00a615f78b8f03ff2cc60fdf0fc7c2.zip
cpython-38ce9c294b00a615f78b8f03ff2cc60fdf0fc7c2.tar.gz
cpython-38ce9c294b00a615f78b8f03ff2cc60fdf0fc7c2.tar.bz2
backport the security fix part of r67246
-rw-r--r--Lib/test/test_descr.py19
-rw-r--r--Misc/NEWS3
-rw-r--r--Objects/typeobject.c2
3 files changed, 24 insertions, 0 deletions
diff --git a/Lib/test/test_descr.py b/Lib/test/test_descr.py
index a31a9f0..cd3d952 100644
--- a/Lib/test/test_descr.py
+++ b/Lib/test/test_descr.py
@@ -4087,6 +4087,24 @@ def notimplemented():
check(iexpr, c, N1)
check(iexpr, c, N2)
+def test_lost_getattr():
+ # issue 4230
+ import gc
+ class EvilGetattribute(object):
+ def __getattr__(self, name):
+ raise AttributeError(name)
+ def __getattribute__(self, name):
+ del EvilGetattribute.__getattr__
+ for i in range(5):
+ gc.collect()
+ raise AttributeError(name)
+
+ try:
+ # This used to segfault
+ EvilGetattribute().attr
+ except AttributeError:
+ pass
+
def test_main():
weakref_segfault() # Must be first, somehow
wrapper_segfault()
@@ -4183,6 +4201,7 @@ def test_main():
vicious_descriptor_nonsense()
test_init()
notimplemented()
+ test_lost_getattr()
if verbose: print "All OK"
diff --git a/Misc/NEWS b/Misc/NEWS
index 320e753..3d6a801 100644
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -12,6 +12,9 @@ What's New in Python 2.4.6c1?
Core and builtins
-----------------
+- Issue #4230: Fix a crash when a class has a custom __getattr__ and an
+ __getattribute__ method that deletes the __getattr__ attribute.
+
- Apply security patches from Apple. CVE-2008-2315.
- Issue #2620: Overflow checking when allocating or reallocating memory
diff --git a/Objects/typeobject.c b/Objects/typeobject.c
index 295634c..2618fb3 100644
--- a/Objects/typeobject.c
+++ b/Objects/typeobject.c
@@ -4594,6 +4594,7 @@ slot_tp_getattr_hook(PyObject *self, PyObject *name)
tp->tp_getattro = slot_tp_getattro;
return slot_tp_getattro(self, name);
}
+ Py_INCREF(getattr);
getattribute = _PyType_Lookup(tp, getattribute_str);
if (getattribute == NULL ||
(getattribute->ob_type == &PyWrapperDescr_Type &&
@@ -4606,6 +4607,7 @@ slot_tp_getattr_hook(PyObject *self, PyObject *name)
PyErr_Clear();
res = PyObject_CallFunction(getattr, "OO", self, name);
}
+ Py_DECREF(getattr);
return res;
}