mirror of
https://github.com/python/cpython.git
synced 2025-07-24 03:35:53 +00:00
bpo-31758: Prevent crashes when using an uninitialized _elementtree.XMLParser object (GH-3997)
This commit is contained in:
parent
63e5b59c06
commit
402e1cdb13
3 changed files with 41 additions and 0 deletions
|
@ -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)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue