Eina: Fix issue in the XML parser when a tag was in a comment or a CDATA.
authorcaro <caro@7cbeb6ba-43b4-40fd-8cce-4c39aea84d33>
Tue, 29 May 2012 22:00:29 +0000 (22:00 +0000)
committercaro <caro@7cbeb6ba-43b4-40fd-8cce-4c39aea84d33>
Tue, 29 May 2012 22:00:29 +0000 (22:00 +0000)
git-svn-id: svn+ssh://svn.enlightenment.org/var/svn/e/trunk/eina@71518 7cbeb6ba-43b4-40fd-8cce-4c39aea84d33

ChangeLog
NEWS
src/lib/eina_simple_xml_parser.c
src/tests/sample.gpx

index b224389..7e674e0 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
         * remove --disable-posix-threads and --disable-win32-threads
        from configure options, and detect automatically the threading
        support.
+       Fix bug in the XML parser when a tag was in a comment or a
+       cdata
 
diff --git a/NEWS b/NEWS
index 5e65a19..f53279e 100644 (file)
--- a/NEWS
+++ b/NEWS
@@ -14,6 +14,7 @@ Fixes:
     and PPC).
     * Portability issue with Eina_Value test suite when unsigned where not promoted to
     unsigned long (case on Itanium).
+    * Fix issue in the XML parser when a tag was in a comment or a CDATA.
 
 Eina 1.2.0
 
index 4e357ba..9a6c649 100644 (file)
@@ -159,6 +159,28 @@ _eina_simple_xml_tag_end_find(const char *itr, const char *itr_end)
    return NULL;
 }
 
+static inline const char *
+_eina_simple_xml_tag_comment_end_find(const char *itr, const char *itr_end)
+{
+   for (; itr < itr_end; itr++)
+     if ((*itr == '-') &&
+         ((itr + 1 < itr_end) && (*(itr + 1) == '-')) &&
+         ((itr + 2 < itr_end) && (*(itr + 2) == '>')))
+       return itr + 2;
+   return NULL;
+}
+
+static inline const char *
+_eina_simple_xml_tag_cdata_end_find(const char *itr, const char *itr_end)
+{
+   for (; itr < itr_end; itr++)
+     if ((*itr == ']') &&
+         ((itr + 1 < itr_end) && (*(itr + 1) == ']')) &&
+         ((itr + 2 < itr_end) && (*(itr + 2) == '>')))
+       return itr + 2;
+   return NULL;
+}
+
 /**
  * @endcond
  */
@@ -342,21 +364,17 @@ eina_simple_xml_parse(const char *buf, unsigned buflen, Eina_Bool strip, Eina_Si
                        toff = 0;
                     }
 
-                  p = _eina_simple_xml_tag_end_find(itr + 1 + toff, itr_end);
-                  if (p)
-                    {
-                       if (type == EINA_SIMPLE_XML_CDATA)
-                         {
-                            /* must end with ]]> */
-                            while ((p) && (memcmp(p - 2, "]]>", 3)))
-                              p = _eina_simple_xml_tag_end_find(p + 1, itr_end);
-                         }
+                  if (type == EINA_SIMPLE_XML_CDATA)
+                    p = _eina_simple_xml_tag_cdata_end_find(itr + 1 + toff, itr_end);
+                  else if (type == EINA_SIMPLE_XML_COMMENT)
+                    p = _eina_simple_xml_tag_comment_end_find(itr + 1 + toff, itr_end);
+                  else
+                    p = _eina_simple_xml_tag_end_find(itr + 1 + toff, itr_end);
 
-                       if ((p) && (*p == '<'))
-                         {
-                            type = EINA_SIMPLE_XML_ERROR;
-                            toff = 0;
-                         }
+                  if ((p) && (*p == '<'))
+                    {
+                       type = EINA_SIMPLE_XML_ERROR;
+                       toff = 0;
                     }
 
                   if (p)
index e1db971..713ec7d 100644 (file)
@@ -21,4 +21,6 @@
       <trkpt lon="5.62314" lat="53.010303"/>
     </trkseg>
   </trk>
+  <!-- <foo>bar</foo> -->
+  <![CDATA[ <foo>bar</foo> ]]>
 </gpx>