diff options
author | Miss Islington (bot) <31488909+miss-islington@users.noreply.github.com> | 2017-10-10 21:51:28 (GMT) |
---|---|---|
committer | Serhiy Storchaka <storchaka@gmail.com> | 2017-10-10 21:51:28 (GMT) |
commit | a8ac71d15f2a4aef83a8954a678cc12545ce517c (patch) | |
tree | 5148a4db374d2e6f08d4088912b01116ce03c339 /Lib | |
parent | ac360fc56c111ec19895ba445e0ec6863f825625 (diff) | |
download | cpython-a8ac71d15f2a4aef83a8954a678cc12545ce517c.zip cpython-a8ac71d15f2a4aef83a8954a678cc12545ce517c.tar.gz cpython-a8ac71d15f2a4aef83a8954a678cc12545ce517c.tar.bz2 |
[3.6] bpo-31728: Prevent crashes in _elementtree due to unsafe cleanup of Element.text and Element.tail (GH-3924) (#3945)
(cherry picked from commit 39ecb9c71b6e55d8a61a710d0144231bd88f9ada)
Diffstat (limited to 'Lib')
-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 b2200d3..d99b4e7 100644 --- a/Lib/test/test_xml_etree_c.py +++ b/Lib/test/test_xml_etree_c.py @@ -84,6 +84,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): |