]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
bpo-40489: Add test case for dict contain use after free (GH-19906)
authorDong-hee Na <donghee.na92@gmail.com>
Mon, 4 May 2020 17:30:42 +0000 (02:30 +0900)
committerGitHub <noreply@github.com>
Mon, 4 May 2020 17:30:42 +0000 (02:30 +0900)
Lib/test/test_dict.py

index d5a3d9e8945741223b6a20c80ffd48959fd78119..6b8596fff6a9f7f1cb4ae378812632b894d4b4a0 100644 (file)
@@ -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):