From 98ece2c2c668eeb26b29e4d92b4491ed3de7a578 Mon Sep 17 00:00:00 2001 From: caro Date: Tue, 29 May 2012 22:00:29 +0000 Subject: [PATCH] Eina: Fix issue in the XML parser when a tag was in a comment or a CDATA. git-svn-id: http://svn.enlightenment.org/svn/e/trunk/eina@71518 7cbeb6ba-43b4-40fd-8cce-4c39aea84d33 --- ChangeLog | 2 ++ NEWS | 1 + src/lib/eina_simple_xml_parser.c | 46 ++++++++++++++++++++++++++++------------ src/tests/sample.gpx | 2 ++ 4 files changed, 37 insertions(+), 14 deletions(-) diff --git a/ChangeLog b/ChangeLog index b224389..7e674e0 100644 --- a/ChangeLog +++ b/ChangeLog @@ -290,4 +290,6 @@ * 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 --- 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 diff --git a/src/lib/eina_simple_xml_parser.c b/src/lib/eina_simple_xml_parser.c index 4e357ba..9a6c649 100644 --- a/src/lib/eina_simple_xml_parser.c +++ b/src/lib/eina_simple_xml_parser.c @@ -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) diff --git a/src/tests/sample.gpx b/src/tests/sample.gpx index e1db971..713ec7d 100644 --- a/src/tests/sample.gpx +++ b/src/tests/sample.gpx @@ -21,4 +21,6 @@ + + bar ]]> -- 2.7.4