diff options
author | Victor Stinner <victor.stinner@gmail.com> | 2012-03-08 23:39:08 (GMT) |
---|---|---|
committer | Victor Stinner <victor.stinner@gmail.com> | 2012-03-08 23:39:08 (GMT) |
commit | d74782b0ac7dc5c7b8b7ca575829f2f33af66684 (patch) | |
tree | 6d1e5b3968c53611a989c920be47e65b99c3c7e3 /Lib/test/crashers | |
parent | 4dcf474337022ec149c4ed6d90ebafb553e98796 (diff) | |
download | cpython-d74782b0ac7dc5c7b8b7ca575829f2f33af66684.zip cpython-d74782b0ac7dc5c7b8b7ca575829f2f33af66684.tar.gz cpython-d74782b0ac7dc5c7b8b7ca575829f2f33af66684.tar.bz2 |
Close #14199: _PyType_Lookup() and super_getattro() keep a strong reference to
the type MRO to avoid a crash if the MRO is changed during the lookup.
Diffstat (limited to 'Lib/test/crashers')
-rw-r--r-- | Lib/test/crashers/losing_mro_ref.py | 35 |
1 files changed, 0 insertions, 35 deletions
diff --git a/Lib/test/crashers/losing_mro_ref.py b/Lib/test/crashers/losing_mro_ref.py deleted file mode 100644 index b3bcd32..0000000 --- a/Lib/test/crashers/losing_mro_ref.py +++ /dev/null @@ -1,35 +0,0 @@ -""" -There is a way to put keys of any type in a type's dictionary. -I think this allows various kinds of crashes, but so far I have only -found a convoluted attack of _PyType_Lookup(), which uses the mro of the -type without holding a strong reference to it. Probably works with -super.__getattribute__() too, which uses the same kind of code. -""" - -class MyKey(object): - def __hash__(self): - return hash('mykey') - - def __eq__(self, other): - # the following line decrefs the previous X.__mro__ - X.__bases__ = (Base2,) - # trash all tuples of length 3, to make sure that the items of - # the previous X.__mro__ are really garbage - z = [] - for i in range(1000): - z.append((i, None, None)) - return 0 - - -class Base(object): - mykey = 'from Base' - -class Base2(object): - mykey = 'from Base2' - -# you can't add a non-string key to X.__dict__, but it can be -# there from the beginning :-) -X = type('X', (Base,), {MyKey(): 5}) - -print(X.mykey) -# I get a segfault, or a slightly wrong assertion error in a debug build. |