]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
Issue #19815: Fix segfault when parsing empty namespace declaration.
authorEli Bendersky <eliben@gmail.com>
Thu, 28 Nov 2013 14:31:58 +0000 (06:31 -0800)
committerEli Bendersky <eliben@gmail.com>
Thu, 28 Nov 2013 14:31:58 +0000 (06:31 -0800)
Based on patches by Christian Heimes and Vajrasky Kok

Lib/test/test_xml_etree.py
Modules/_elementtree.c

index 54965345c7b08ee2de1da9761a09e9f57cea7e86..7bd8a2c7eea410472258c5729deb2c9b019e49e2 100644 (file)
@@ -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:
index 9bdc4c751c3c50998e6f880ac0f9ee60e23f331a..7e01352fa766f5f5891ed66bc27533dd6829f2f2 100644 (file)
@@ -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;