summaryrefslogtreecommitdiffstats
path: root/Lib/test/test_xml_etree_c.py
diff options
context:
space:
mode:
authorSerhiy Storchaka <storchaka@gmail.com>2021-12-05 12:22:54 (GMT)
committerGitHub <noreply@github.com>2021-12-05 12:22:54 (GMT)
commitd15cdb2f32f572ce56d7120135da24b9fdce4c99 (patch)
tree156e25eedbeddac79d43772dbead201da5d08f5e /Lib/test/test_xml_etree_c.py
parentf42a06ba279c916fb67289e47f9bc60dc5dee4ee (diff)
downloadcpython-d15cdb2f32f572ce56d7120135da24b9fdce4c99.zip
cpython-d15cdb2f32f572ce56d7120135da24b9fdce4c99.tar.gz
cpython-d15cdb2f32f572ce56d7120135da24b9fdce4c99.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.
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):