summaryrefslogtreecommitdiffstats
path: root/Lib/test/test_xml_etree_c.py
diff options
context:
space:
mode:
authorMiss Islington (bot) <31488909+miss-islington@users.noreply.github.com>2021-12-05 19:04:52 (GMT)
committerGitHub <noreply@github.com>2021-12-05 19:04:52 (GMT)
commitbeb834292db54fea129dd073cc822179430cee52 (patch)
treee4a3383665647e721132b178ca028020a725f384 /Lib/test/test_xml_etree_c.py
parentf6648e229edf07a1e4897244d7d34989dd9ea647 (diff)
downloadcpython-beb834292db54fea129dd073cc822179430cee52.zip
cpython-beb834292db54fea129dd073cc822179430cee52.tar.gz
cpython-beb834292db54fea129dd073cc822179430cee52.tar.bz2
bpo-27946: Fix possible crash in ElementTree.Element (GH-29915)
Getting an attribute via attrib.get() simultaneously with replacing the attrib dict can lead to access to deallocated dict. (cherry picked from commit d15cdb2f32f572ce56d7120135da24b9fdce4c99) Co-authored-by: Serhiy Storchaka <storchaka@gmail.com>
Diffstat (limited to 'Lib/test/test_xml_etree_c.py')
-rw-r--r--Lib/test/test_xml_etree_c.py12
1 files changed, 12 insertions, 0 deletions
diff --git a/Lib/test/test_xml_etree_c.py b/Lib/test/test_xml_etree_c.py
index e68613b..bec8208 100644
--- a/Lib/test/test_xml_etree_c.py
+++ b/Lib/test/test_xml_etree_c.py
@@ -169,6 +169,18 @@ class MiscTests(unittest.TestCase):
del parser
support.gc_collect()
+ def test_dict_disappearing_during_get_item(self):
+ # test fix for seg fault reported in issue 27946
+ class X:
+ def __hash__(self):
+ e.attrib = {} # this frees e->extra->attrib
+ [{i: i} for i in range(1000)] # exhaust the dict keys cache
+ return 13
+
+ e = cET.Element("elem", {1: 2})
+ r = e.get(X())
+ self.assertIsNone(r)
+
@unittest.skipUnless(cET, 'requires _elementtree')
class TestAliasWorking(unittest.TestCase):