Thomas Wouters | 0e3f591 | 2006-08-11 14:57:12 +0000 | [diff] [blame] | 1 | """ |
| 2 | _PyType_Lookup() returns a borrowed reference. |
| 3 | This attacks PyObject_GenericSetAttr(). |
| 4 | |
| 5 | NB. on my machine this crashes in 2.5 debug but not release. |
| 6 | """ |
| 7 | |
| 8 | class A(object): |
| 9 | pass |
| 10 | |
| 11 | class B(object): |
| 12 | def __del__(self): |
Guido van Rossum | be19ed7 | 2007-02-09 05:37:30 +0000 | [diff] [blame] | 13 | print("hi") |
Thomas Wouters | 0e3f591 | 2006-08-11 14:57:12 +0000 | [diff] [blame] | 14 | del C.d |
| 15 | |
| 16 | class D(object): |
| 17 | def __set__(self, obj, value): |
| 18 | self.hello = 42 |
| 19 | |
| 20 | class C(object): |
| 21 | d = D() |
| 22 | |
| 23 | def g(): |
| 24 | pass |
| 25 | |
| 26 | |
| 27 | c = C() |
| 28 | a = A() |
| 29 | a.cycle = a |
| 30 | a.other = B() |
| 31 | |
| 32 | lst = [None] * 1000000 |
| 33 | i = 0 |
| 34 | del a |
| 35 | while 1: |
Christian Heimes | ff73795 | 2007-11-27 10:40:20 +0000 | [diff] [blame] | 36 | c.d = 42 # segfaults in PyMethod_New(__func__=D.__set__, __self__=d) |
Thomas Wouters | 0e3f591 | 2006-08-11 14:57:12 +0000 | [diff] [blame] | 37 | lst[i] = c.g # consume the free list of instancemethod objects |
| 38 | i += 1 |