summaryrefslogtreecommitdiffstats
path: root/Lib/test/test_exceptions.py
diff options
context:
space:
mode:
authorGeorg Brandl <georg@python.org>2009-03-31 04:16:10 (GMT)
committerGeorg Brandl <georg@python.org>2009-03-31 04:16:10 (GMT)
commitab6f2f6eb680c40750f05de4bc7cf8964b733b74 (patch)
tree77f3d4c83191b1cc077683af03a94681ce917cdb /Lib/test/test_exceptions.py
parent71095ea4ce1b8584d89047f2256b183d40cc9d35 (diff)
downloadcpython-ab6f2f6eb680c40750f05de4bc7cf8964b733b74.zip
cpython-ab6f2f6eb680c40750f05de4bc7cf8964b733b74.tar.gz
cpython-ab6f2f6eb680c40750f05de4bc7cf8964b733b74.tar.bz2
Fix segfaults when running test_exceptions with coverage tracing, caused by wrongly defining Exception.__context__ as a T_OBJECT structmember which does not set the member to NULL on None assignment, and generally does not do type checks. This could be used to crash the interpreter by setting any object to __context__. The same applies to __cause__. Also document the PyException_* functions.
Diffstat (limited to 'Lib/test/test_exceptions.py')
-rw-r--r--Lib/test/test_exceptions.py6
1 files changed, 6 insertions, 0 deletions
diff --git a/Lib/test/test_exceptions.py b/Lib/test/test_exceptions.py
index b671cbc..8bb2079 100644
--- a/Lib/test/test_exceptions.py
+++ b/Lib/test/test_exceptions.py
@@ -341,6 +341,12 @@ class ExceptionTests(unittest.TestCase):
else:
self.fail("No exception raised")
+ def testInvalidAttrs(self):
+ self.assertRaises(TypeError, setattr, Exception(), '__cause__', 1)
+ self.assertRaises(TypeError, delattr, Exception(), '__cause__')
+ self.assertRaises(TypeError, setattr, Exception(), '__context__', 1)
+ self.assertRaises(TypeError, delattr, Exception(), '__context__')
+
def testNoneClearsTracebackAttr(self):
try:
raise IndexError(4)