diff options
author | Eli Bendersky <eliben@gmail.com> | 2013-11-28 06:31:58 -0800 |
---|---|---|
committer | Eli Bendersky <eliben@gmail.com> | 2013-11-28 06:31:58 -0800 |
commit | aa0adb51e2f787ad7cb384d90d2405e5e1280bb9 (patch) | |
tree | 6ef375af11ee78c194e2ebd09a6e738f996285c8 | |
parent | 98bacffbe95cbcdee00a81f00a6ea2b26cfbb41d (diff) | |
download | cpython-aa0adb51e2f787ad7cb384d90d2405e5e1280bb9.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 54965345c7..7bd8a2c7ee 100644 --- a/Lib/test/test_xml_etree.py +++ b/Lib/test/test_xml_etree.py @@ -535,6 +535,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 9bdc4c751c..7e01352fa7 100644 --- a/Modules/_elementtree.c +++ b/Modules/_elementtree.c @@ -2997,7 +2997,10 @@ expat_start_ns_handler(XMLParserObject* self, const XML_Char* prefix, PyObject* sprefix = NULL; PyObject* suri = NULL; - suri = PyUnicode_DecodeUTF8(uri, strlen(uri), "strict"); + if (uri) + suri = PyUnicode_DecodeUTF8(uri, strlen(uri), "strict"); + else + suri = PyUnicode_FromString(""); if (!suri) return; |