diff options
author | Zackery Spytz <zspytz@gmail.com> | 2019-12-30 19:32:58 (GMT) |
---|---|---|
committer | Pablo Galindo <Pablogsal@gmail.com> | 2019-12-30 19:32:58 (GMT) |
commit | d9e561d23d994e3ed15f4fcbd7ee5c8fe50f190b (patch) | |
tree | 34162f9f568287e72843c154831efb35b2384a55 /Lib/test/test_list.py | |
parent | 09c482fad11c769be38b2449f1056e264b701bb7 (diff) | |
download | cpython-d9e561d23d994e3ed15f4fcbd7ee5c8fe50f190b.zip cpython-d9e561d23d994e3ed15f4fcbd7ee5c8fe50f190b.tar.gz cpython-d9e561d23d994e3ed15f4fcbd7ee5c8fe50f190b.tar.bz2 |
bpo-38610: Fix possible crashes in several list methods (GH-17022)
Hold strong references to list elements while calling PyObject_RichCompareBool().
Diffstat (limited to 'Lib/test/test_list.py')
-rw-r--r-- | Lib/test/test_list.py | 26 |
1 files changed, 26 insertions, 0 deletions
diff --git a/Lib/test/test_list.py b/Lib/test/test_list.py index fe4b2cd..b10a833 100644 --- a/Lib/test/test_list.py +++ b/Lib/test/test_list.py @@ -171,5 +171,31 @@ class ListTest(list_tests.CommonTest): self.assertEqual(iter_size, sys.getsizeof(list([0] * 10))) self.assertEqual(iter_size, sys.getsizeof(list(range(10)))) + def test_count_index_remove_crashes(self): + # bpo-38610: The count(), index(), and remove() methods were not + # holding strong references to list elements while calling + # PyObject_RichCompareBool(). + class X: + def __eq__(self, other): + lst.clear() + return NotImplemented + + lst = [X()] + with self.assertRaises(ValueError): + lst.index(lst) + + class L(list): + def __eq__(self, other): + str(other) + return NotImplemented + + lst = L([X()]) + lst.count(lst) + + lst = L([X()]) + with self.assertRaises(ValueError): + lst.remove(lst) + + if __name__ == "__main__": unittest.main() |