Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

gh-120298: Fix use-after-free in list_richcompare_impl #120303

Merged
merged 3 commits into from
Jun 11, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 0 additions & 10 deletions Lib/test/test_bisect.py
Original file line number Diff line number Diff line change
Expand Up @@ -291,16 +291,6 @@ def __gt__(self, other):
self.assertEqual(i1, 40)
self.assertEqual(i2, 41)

def test_use_after_free_gh120298(self):
class evil(object):
def __lt__(self, other):
other.clear()
return NotImplemented

a = [[evil()]]
with self.assertRaises(TypeError):
self.module.insort_left(a, a)

class TestBisectPython(TestBisect, unittest.TestCase):
module = py_bisect

Expand Down
12 changes: 0 additions & 12 deletions Lib/test/test_deque.py
Original file line number Diff line number Diff line change
Expand Up @@ -782,18 +782,6 @@ def test_runtime_error_on_empty_deque(self):
d.append(10)
self.assertRaises(RuntimeError, next, it)

def test_use_after_free_gh120298(self):
class evil(object):
def __lt__(self, other):
other.pop()
return NotImplemented

a = [[[evil()]]]
b = deque(a[0])
c = deque(a)
with self.assertRaises(TypeError):
b < c

class Deque(deque):
pass

Expand Down
11 changes: 11 additions & 0 deletions Lib/test/test_list.py
Original file line number Diff line number Diff line change
Expand Up @@ -234,6 +234,17 @@ def __eq__(self, other):
list4 = [1]
self.assertFalse(list3 == list4)

def test_lt_operator_modifying_operand(self):
# See gh-120298
class evil(object):
sobolevn marked this conversation as resolved.
Show resolved Hide resolved
def __lt__(self, other):
other.clear()
return NotImplemented

a = [[evil()]]
with self.assertRaises(TypeError):
a[0] < a

@cpython_only
def test_preallocation(self):
iterable = [0] * 10
Expand Down
Loading