From 785f5e6d674306052bf865677d885c30561985ae Mon Sep 17 00:00:00 2001 From: Dong-hee Na Date: Tue, 5 May 2020 02:30:42 +0900 Subject: bpo-40489: Add test case for dict contain use after free (GH-19906) --- Lib/test/test_dict.py | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/Lib/test/test_dict.py b/Lib/test/test_dict.py index d5a3d9e..6b8596f 100644 --- a/Lib/test/test_dict.py +++ b/Lib/test/test_dict.py @@ -1324,6 +1324,19 @@ class DictTest(unittest.TestCase): d = {0: set()} (0, X()) in d.items() + def test_dict_contain_use_after_free(self): + # bpo-40489 + class S(str): + def __eq__(self, other): + d.clear() + return NotImplemented + + def __hash__(self): + return hash('test') + + d = {S(): 'value'} + self.assertFalse('test' in d) + def test_init_use_after_free(self): class X: def __hash__(self): -- cgit v0.12