[Python-checkins] cpython (merge 3.3 -> default): Issue #19815: Fix segfault when parsing empty namespace declaration.

eli.bendersky python-checkins at python.org
Thu Nov 28 15:35:47 CET 2013


http://hg.python.org/cpython/rev/2b2925c08a6c
changeset:   87627:2b2925c08a6c
parent:      87623:87858e0b757d
parent:      87626:712ebde527c2
user:        Eli Bendersky <eliben at gmail.com>
date:        Thu Nov 28 06:35:40 2013 -0800
summary:
  Issue #19815: Fix segfault when parsing empty namespace declaration.

Based on patches by Christian Heimes and Vajrasky Kok

files:
  Lib/test/test_xml_etree.py |  5 +++++
  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
--- a/Lib/test/test_xml_etree.py
+++ b/Lib/test/test_xml_etree.py
@@ -526,6 +526,11 @@
                 ('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
--- a/Modules/_elementtree.c
+++ b/Modules/_elementtree.c
@@ -3038,7 +3038,10 @@
     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;
 

-- 
Repository URL: http://hg.python.org/cpython


More information about the Python-checkins mailing list