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

eli.bendersky python-checkins at python.org
Thu Nov 28 15:25:49 CET 2013


http://hg.python.org/cpython/rev/395a266bcb5a
changeset:   87624:395a266bcb5a
branch:      2.7
parent:      87609:e5b7f140ae30
user:        Eli Bendersky <eliben at gmail.com>
date:        Thu Nov 28 06:25:45 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 |  11 +++++++++--
  Modules/_elementtree.c     |   5 ++++-
  2 files changed, 13 insertions(+), 3 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
@@ -713,14 +713,21 @@
     end {namespace}root
     end-ns None
 
+    >>> import StringIO
+
+    >>> events = ('start-ns', 'end-ns')
+    >>> context = ET.iterparse(StringIO.StringIO(r"<root xmlns=''/>"), events)
+    >>> for action, elem in context:
+    ...   print action, elem
+    start-ns ('', '')
+    end-ns None
+
     >>> events = ("start", "end", "bogus")
     >>> with open(SIMPLE_XMLFILE, "rb") as f:
     ...     iterparse(f, events)
     Traceback (most recent call last):
     ValueError: unknown event 'bogus'
 
-    >>> import StringIO
-
     >>> source = StringIO.StringIO(
     ...     "<?xml version='1.0' encoding='iso-8859-1'?>\\n"
     ...     "<body xmlns='http://éffbot.org/ns'\\n"
diff --git a/Modules/_elementtree.c b/Modules/_elementtree.c
--- a/Modules/_elementtree.c
+++ b/Modules/_elementtree.c
@@ -2338,7 +2338,10 @@
     PyObject* sprefix = NULL;
     PyObject* suri = NULL;
 
-    suri = makestring(uri, strlen(uri));
+    if (uri)
+      suri = makestring(uri, strlen(uri));
+    else
+      suri = PyString_FromStringAndSize("", 0);
     if (!suri)
         return;
 

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


More information about the Python-checkins mailing list