summaryrefslogtreecommitdiffstats
path: root/Lib/test
diff options
context:
space:
mode:
authorMiss Islington (bot) <31488909+miss-islington@users.noreply.github.com>2020-04-12 15:18:57 (GMT)
committerGitHub <noreply@github.com>2020-04-12 15:18:57 (GMT)
commit61511488cf4e7a1cb57a38efba7e0a84a387fe58 (patch)
tree5060fb11a6fb596fe956d81c03a62008e6ca6dc0 /Lib/test
parentee249d798ba08f065efbf4f450880a446c6ca49d (diff)
downloadcpython-61511488cf4e7a1cb57a38efba7e0a84a387fe58.zip
cpython-61511488cf4e7a1cb57a38efba7e0a84a387fe58.tar.gz
cpython-61511488cf4e7a1cb57a38efba7e0a84a387fe58.tar.bz2
bpo-31758: Prevent crashes when using an uninitialized _elementtree.XMLParser object (GH-3997) (GH-19485)
(cherry picked from commit 402e1cdb132f384e4dcde7a3d7ec7ea1fc7ab527)
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 2144d20..e26e171 100644
--- a/Lib/test/test_xml_etree_c.py
+++ b/Lib/test/test_xml_etree_c.py
@@ -118,6 +118,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)