From 96bfc84a12e7864afee2269019c6f2c833ac5d97 Mon Sep 17 00:00:00 2001 From: Vincent Torri 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. SVN revision: 71518 --- legacy/eina/ChangeLog | 2 + legacy/eina/NEWS | 1 + legacy/eina/src/lib/eina_simple_xml_parser.c | 46 ++++++++++++++------ legacy/eina/src/tests/sample.gpx | 2 + 4 files changed, 37 insertions(+), 14 deletions(-) diff --git a/legacy/eina/ChangeLog b/legacy/eina/ChangeLog index b224389f0f..7e674e094c 100644 --- a/legacy/eina/ChangeLog +++ b/legacy/eina/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/legacy/eina/NEWS b/legacy/eina/NEWS index 5e65a196e4..f53279e662 100644 --- a/legacy/eina/NEWS +++ b/legacy/eina/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/legacy/eina/src/lib/eina_simple_xml_parser.c b/legacy/eina/src/lib/eina_simple_xml_parser.c index 4e357ba2b3..9a6c649a06 100644 --- a/legacy/eina/src/lib/eina_simple_xml_parser.c +++ b/legacy/eina/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/legacy/eina/src/tests/sample.gpx b/legacy/eina/src/tests/sample.gpx index e1db971efa..713ec7df65 100644 --- a/legacy/eina/src/tests/sample.gpx +++ b/legacy/eina/src/tests/sample.gpx @@ -21,4 +21,6 @@ + + bar ]]>