diff options
| author | Eli Bendersky <eliben@gmail.com> | 2013-11-28 06:35:40 -0800 |
|---|---|---|
| committer | Eli Bendersky <eliben@gmail.com> | 2013-11-28 06:35:40 -0800 |
| commit | 8148164353b935ce7a1716d82eca461e0ca6ed8f (patch) | |
| tree | 5cf162b1aecf6bc508504e1c800866feff7d6fe5 | |
| parent | 470fba1f9f3e3296df675fdd7d37102065cfb6ae (diff) | |
| parent | 4b79518f83fa6c4dadd69326276032d74c8e3df7 (diff) | |
| download | cpython-git-8148164353b935ce7a1716d82eca461e0ca6ed8f.tar.gz | |
Issue #19815: Fix segfault when parsing empty namespace declaration.
Based on patches by Christian Heimes and Vajrasky Kok
| -rw-r--r-- | Lib/test/test_xml_etree.py | 5 | ||||
| -rw-r--r-- | Modules/_elementtree.c | 5 |
2 files changed, 9 insertions, 1 deletions
diff --git a/Lib/test/test_xml_etree.py b/Lib/test/test_xml_etree.py index 5351b0b82e..89971f16ca 100644 --- a/Lib/test/test_xml_etree.py +++ b/Lib/test/test_xml_etree.py @@ -526,6 +526,11 @@ class ElementTreeTest(unittest.TestCase): ('end-ns', None), ]) + events = ('start-ns', 'end-ns') + context = iterparse(io.StringIO(r"<root xmlns=''/>"), events) + res = [action for action, elem in context] + self.assertEqual(res, ['start-ns', 'end-ns']) + events = ("start", "end", "bogus") with self.assertRaises(ValueError) as cm: with open(SIMPLE_XMLFILE, "rb") as f: diff --git a/Modules/_elementtree.c b/Modules/_elementtree.c index 46a1f4157c..b3b6976708 100644 --- a/Modules/_elementtree.c +++ b/Modules/_elementtree.c @@ -3038,7 +3038,10 @@ expat_start_ns_handler(XMLParserObject* self, const XML_Char* prefix, if (PyErr_Occurred()) return; - suri = PyUnicode_DecodeUTF8(uri, strlen(uri), "strict"); + if (uri) + suri = PyUnicode_DecodeUTF8(uri, strlen(uri), "strict"); + else + suri = PyUnicode_FromString(""); if (!suri) return; |
