mirror of
https://github.com/python/cpython.git
synced 2025-10-09 08:31:26 +00:00
bpo-38588: Fix possible crashes in dict and list when calling PyObject_RichCompareBool (GH-17734)
Take strong references before calling PyObject_RichCompareBool to protect against the case where the object dies during the call.
This commit is contained in:
parent
ee9ff05ec2
commit
2d5bf568ea
5 changed files with 47 additions and 1 deletions
|
@ -163,6 +163,31 @@ class ListTest(list_tests.CommonTest):
|
|||
with self.assertRaises(TypeError):
|
||||
(3,) + L([1,2])
|
||||
|
||||
def test_equal_operator_modifying_operand(self):
|
||||
# test fix for seg fault reported in bpo-38588 part 2.
|
||||
class X:
|
||||
def __eq__(self,other) :
|
||||
list2.clear()
|
||||
return NotImplemented
|
||||
|
||||
class Y:
|
||||
def __eq__(self, other):
|
||||
list1.clear()
|
||||
return NotImplemented
|
||||
|
||||
class Z:
|
||||
def __eq__(self, other):
|
||||
list3.clear()
|
||||
return NotImplemented
|
||||
|
||||
list1 = [X()]
|
||||
list2 = [Y()]
|
||||
self.assertTrue(list1 == list2)
|
||||
|
||||
list3 = [Z()]
|
||||
list4 = [1]
|
||||
self.assertFalse(list3 == list4)
|
||||
|
||||
@cpython_only
|
||||
def test_preallocation(self):
|
||||
iterable = [0] * 10
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue