summaryrefslogtreecommitdiffstats
path: root/Lib/test
diff options
context:
space:
mode:
authorDonghee Na <donghee.na@python.org>2024-08-22 14:49:09 (GMT)
committerGitHub <noreply@github.com>2024-08-22 14:49:09 (GMT)
commit297f2e093ec95800ae2184330b8408c875523467 (patch)
tree5c1b6debe984d76e5874136146b854f98847cbb4 /Lib/test
parent4abc1c1456413f3d2692257545a33bb16b24f900 (diff)
downloadcpython-297f2e093ec95800ae2184330b8408c875523467.zip
cpython-297f2e093ec95800ae2184330b8408c875523467.tar.gz
cpython-297f2e093ec95800ae2184330b8408c875523467.tar.bz2
gh-123083: Fix a potential use-after-free in ``STORE_ATTR_WITH_HINT`` (gh-123092)
Diffstat (limited to 'Lib/test')
-rw-r--r--Lib/test/test_dict.py18
1 files changed, 18 insertions, 0 deletions
diff --git a/Lib/test/test_dict.py b/Lib/test/test_dict.py
index e5dba7c..4030716 100644
--- a/Lib/test/test_dict.py
+++ b/Lib/test/test_dict.py
@@ -1476,6 +1476,24 @@ class DictTest(unittest.TestCase):
gc.collect()
self.assertTrue(gc.is_tracked(next(it)))
+ def test_store_evilattr(self):
+ class EvilAttr:
+ def __init__(self, d):
+ self.d = d
+
+ def __del__(self):
+ if 'attr' in self.d:
+ del self.d['attr']
+ gc.collect()
+
+ class Obj:
+ pass
+
+ obj = Obj()
+ obj.__dict__ = {}
+ for _ in range(10):
+ obj.attr = EvilAttr(obj.__dict__)
+
def test_str_nonstr(self):
# cpython uses a different lookup function if the dict only contains
# `str` keys. Make sure the unoptimized path is used when a non-`str`