diff options
author | Oren Milman <orenmn@gmail.com> | 2017-10-10 20:26:24 (GMT) |
---|---|---|
committer | Serhiy Storchaka <storchaka@gmail.com> | 2017-10-10 20:26:24 (GMT) |
commit | 39ecb9c71b6e55d8a61a710d0144231bd88f9ada (patch) | |
tree | 6cff8890ff67016e555ae35d3ee5d51e0c1a8b0b /Lib/test/test_xml_etree_c.py | |
parent | 93c5a5df8ea118f6e4a153a7c8cccd65a5ff8bff (diff) | |
download | cpython-39ecb9c71b6e55d8a61a710d0144231bd88f9ada.zip cpython-39ecb9c71b6e55d8a61a710d0144231bd88f9ada.tar.gz cpython-39ecb9c71b6e55d8a61a710d0144231bd88f9ada.tar.bz2 |
bpo-31728: Prevent crashes in _elementtree due to unsafe cleanup of Element.text and Element.tail (#3924)
Diffstat (limited to 'Lib/test/test_xml_etree_c.py')
-rw-r--r-- | Lib/test/test_xml_etree_c.py | 32 |
1 files changed, 32 insertions, 0 deletions
diff --git a/Lib/test/test_xml_etree_c.py b/Lib/test/test_xml_etree_c.py index 25517a7..765652f 100644 --- a/Lib/test/test_xml_etree_c.py +++ b/Lib/test/test_xml_etree_c.py @@ -85,6 +85,38 @@ class MiscTests(unittest.TestCase): # and so destroy the parser support.gc_collect() + def test_bpo_31728(self): + # A crash or an assertion failure shouldn't happen, in case garbage + # collection triggers a call to clear() or a reading of text or tail, + # while a setter or clear() or __setstate__() is already running. + elem = cET.Element('elem') + class X: + def __del__(self): + elem.text + elem.tail + elem.clear() + + elem.text = X() + elem.clear() # shouldn't crash + + elem.tail = X() + elem.clear() # shouldn't crash + + elem.text = X() + elem.text = X() # shouldn't crash + elem.clear() + + elem.tail = X() + elem.tail = X() # shouldn't crash + elem.clear() + + elem.text = X() + elem.__setstate__({'tag': 42}) # shouldn't cause an assertion failure + elem.clear() + + elem.tail = X() + elem.__setstate__({'tag': 42}) # shouldn't cause an assertion failure + @unittest.skipUnless(cET, 'requires _elementtree') class TestAliasWorking(unittest.TestCase): |