summaryrefslogtreecommitdiffstats
path: root/Lib/test
diff options
context:
space:
mode:
authorOren Milman <orenmn@gmail.com>2020-04-12 14:36:41 (GMT)
committerGitHub <noreply@github.com>2020-04-12 14:36:41 (GMT)
commit402e1cdb132f384e4dcde7a3d7ec7ea1fc7ab527 (patch)
tree9ed9857fa40f65bac510c2c04e7dc4a6a706c8c1 /Lib/test
parent63e5b59c06fc99f95d274e7f181296e094cc3ee7 (diff)
downloadcpython-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.py15
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)