[Expat-checkins] expat/lib expat.h, 1.74, 1.75 xmlparse.c, 1.141, 1.142

Karl Waclawek kwaclaw at users.sourceforge.net
Fri Dec 24 19:00:31 CET 2004


Update of /cvsroot/expat/expat/lib
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv16464

Modified Files:
	expat.h xmlparse.c 
Log Message:
Fix for bug # 695407: Reserved prefixes and namespace names.
Contributed by Peter van der Beken.

Index: expat.h
===================================================================
RCS file: /cvsroot/expat/expat/lib/expat.h,v
retrieving revision 1.74
retrieving revision 1.75
diff -u -d -r1.74 -r1.75
--- expat.h	20 Dec 2004 03:19:09 -0000	1.74
+++ expat.h	24 Dec 2004 18:00:28 -0000	1.75
@@ -91,7 +91,11 @@
   XML_ERROR_NOT_SUSPENDED,
   XML_ERROR_ABORTED,
   XML_ERROR_FINISHED,
-  XML_ERROR_SUSPEND_PE
+  XML_ERROR_SUSPEND_PE,
+  /* Added in 2.0. */
+  XML_ERROR_RESERVED_PREFIX_XML,
+  XML_ERROR_RESERVED_PREFIX_XMLNS,
+  XML_ERROR_RESERVED_NAMESPACE_URI
 };
 
 enum XML_Content_Type {

Index: xmlparse.c
===================================================================
RCS file: /cvsroot/expat/expat/lib/xmlparse.c,v
retrieving revision 1.141
retrieving revision 1.142
diff -u -d -r1.141 -r1.142
--- xmlparse.c	24 Dec 2004 16:30:25 -0000	1.141
+++ xmlparse.c	24 Dec 2004 18:00:28 -0000	1.142
@@ -1877,7 +1877,10 @@
     XML_L("parser not suspended"),
     XML_L("parsing aborted"),
     XML_L("parsing finished"),
-    XML_L("cannot suspend in external parameter entity")
+    XML_L("cannot suspend in external parameter entity"),
+    XML_L("reserved prefix (xml) must not be undeclared or bound to another namespace name"),
+    XML_L("reserved prefix (xmlns) must not be declared or undeclared"),
+    XML_L("prefix must not be bound to one of the reserved namespace names")
   };
   if (code > 0 && code < sizeof(message)/sizeof(message[0]))
     return message[code];
@@ -2931,8 +2934,64 @@
   if (*uri == XML_T('\0') && prefix->name)
     return XML_ERROR_UNDECLARING_PREFIX;
 
-  for (len = 0; uri[len]; len++)
-    ;
+  if (ns) {
+    static const XML_Char xmlNamespace[] = {
+      'h', 't', 't', 'p', ':', '/', '/',
+      'w', 'w', 'w', '.', 'w', '3', '.', 'o', 'r', 'g', '/',
+      'X', 'M', 'L', '/', '1', '9', '9', '8', '/',
+      'n', 'a', 'm', 'e', 's', 'p', 'a', 'c', 'e', '\0'
+    };
+    static const int xmlLen = 
+      (int)sizeof(xmlNamespace)/sizeof(XML_Char) - 1;
+    static const XML_Char xmlnsNamespace[] = {
+      'h', 't', 't', 'p', ':', '/', '/',
+      'w', 'w', 'w', '.', 'w', '3', '.', 'o', 'r', 'g', '/',
+      '2', '0', '0', '0', '/', 'x', 'm', 'l', 'n', 's', '/', '\0'
+    };
+    static const int xmlnsLen = 
+      (int)sizeof(xmlnsNamespace)/sizeof(XML_Char) - 1;
+
+    XML_Bool mustBeXML = XML_FALSE;
+    XML_Bool isXML = XML_TRUE;
+    XML_Bool isXMLNS = XML_TRUE;
+
+    if (prefix->name
+        && prefix->name[0] == XML_T('x')
+        && prefix->name[1] == XML_T('m')
+        && prefix->name[2] == XML_T('l')) {
+
+      /* Not allowed to bind xmlns */
+      if (prefix->name[3] == XML_T('n')
+          && prefix->name[4] == XML_T('s')
+          && prefix->name[5] == XML_T('\0'))
+        return XML_ERROR_RESERVED_PREFIX_XMLNS;
+
+      if (prefix->name[3] == XML_T('\0'))
+        mustBeXML = XML_TRUE;
+    }
+
+    for (len = 0; uri[len]; len++) {
+      if (isXML && (len > xmlLen || uri[len] != xmlNamespace[len]))
+        isXML = XML_FALSE;
+
+      if (!mustBeXML && isXMLNS 
+          && (len > xmlnsLen || uri[len] != xmlnsNamespace[len]))
+        isXMLNS = XML_FALSE;
+    }
+    isXML = isXML && len == xmlLen;
+    isXMLNS = isXMLNS && len == xmlnsLen;
+
+    if (mustBeXML != isXML)
+      return mustBeXML ? XML_ERROR_RESERVED_PREFIX_XML
+                       : XML_ERROR_RESERVED_NAMESPACE_URI;
+
+    if (isXMLNS)
+      return XML_ERROR_RESERVED_NAMESPACE_URI;
+  }
+  else
+    for (len = 0; uri[len]; len++)
+      ;
+
   if (namespaceSeparator)
     len++;
   if (freeBindingList) {



More information about the Expat-checkins mailing list