diff options
author | Oren Milman <orenmn@gmail.com> | 2020-04-12 14:36:41 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-04-12 14:36:41 (GMT) |
commit | 402e1cdb132f384e4dcde7a3d7ec7ea1fc7ab527 (patch) | |
tree | 9ed9857fa40f65bac510c2c04e7dc4a6a706c8c1 /Lib/test | |
parent | 63e5b59c06fc99f95d274e7f181296e094cc3ee7 (diff) | |
download | cpython-402e1cdb132f384e4dcde7a3d7ec7ea1fc7ab527.zip cpython-402e1cdb132f384e4dcde7a3d7ec7ea1fc7ab527.tar.gz cpython-402e1cdb132f384e4dcde7a3d7ec7ea1fc7ab527.tar.bz2 |
bpo-31758: Prevent crashes when using an uninitialized _elementtree.XMLParser object (GH-3997)
Diffstat (limited to 'Lib/test')
-rw-r--r-- | Lib/test/test_xml_etree_c.py | 15 |
1 files changed, 15 insertions, 0 deletions
diff --git a/Lib/test/test_xml_etree_c.py b/Lib/test/test_xml_etree_c.py index 15496fd..7437e13 100644 --- a/Lib/test/test_xml_etree_c.py +++ b/Lib/test/test_xml_etree_c.py @@ -115,6 +115,21 @@ class MiscTests(unittest.TestCase): elem.tail = X() elem.__setstate__({'tag': 42}) # shouldn't cause an assertion failure + @support.cpython_only + def test_uninitialized_parser(self): + # The interpreter shouldn't crash in case of calling methods or + # accessing attributes of uninitialized XMLParser objects. + parser = cET.XMLParser.__new__(cET.XMLParser) + self.assertRaises(ValueError, parser.close) + self.assertRaises(ValueError, parser.feed, 'foo') + class MockFile: + def read(*args): + return '' + self.assertRaises(ValueError, parser._parse_whole, MockFile()) + self.assertRaises(ValueError, parser._setevents, None) + self.assertIsNone(parser.entity) + self.assertIsNone(parser.target) + def test_setstate_leaks(self): # Test reference leaks elem = cET.Element.__new__(cET.Element) |