summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDong-hee Na <donghee.na92@gmail.com>2020-05-04 17:30:42 (GMT)
committerGitHub <noreply@github.com>2020-05-04 17:30:42 (GMT)
commit785f5e6d674306052bf865677d885c30561985ae (patch)
tree5b3ef3b8047eda870a6c241ca081347950ce4a12
parentcaa3ef284a2e5e5b9bdd6a9e619804122c842d80 (diff)
downloadcpython-785f5e6d674306052bf865677d885c30561985ae.zip
cpython-785f5e6d674306052bf865677d885c30561985ae.tar.gz
cpython-785f5e6d674306052bf865677d885c30561985ae.tar.bz2
bpo-40489: Add test case for dict contain use after free (GH-19906)
-rw-r--r--Lib/test/test_dict.py13
1 files changed, 13 insertions, 0 deletions
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):