summaryrefslogtreecommitdiff
path: root/strings/xml.c
diff options
context:
space:
mode:
authorAlexander Barkov <alexander.barkov@oracle.com>2011-01-18 09:38:41 +0300
committerAlexander Barkov <alexander.barkov@oracle.com>2011-01-18 09:38:41 +0300
commit5574a2cd91eaf76fd2263b38d64d8c617d3c1d02 (patch)
treefe19f7495a00bb6091ce81a4d85aac71ebb440a4 /strings/xml.c
parentafa2ec12d076947d70baa10a5dd4922fa483a1a4 (diff)
downloadmariadb-git-5574a2cd91eaf76fd2263b38d64d8c617d3c1d02.tar.gz
Bug#44332 my_xml_scan reads behind the end of buffer
Problem: the scanner function tested for strings "<![CDATA[" and "-->" without checking input string boundaries, which led to valgrind's "Conditional jump or move depends on uninitialised value(s)" error. Fix: Adding boundary checking. @ mysql-test/r/xml.result @ mysql-test/t/xml.test Adding test @ strings/xml.c Adding a helper function my_xml_parser_prefix_cmp(), with input string boundary check.
Diffstat (limited to 'strings/xml.c')
-rw-r--r--strings/xml.c23
1 files changed, 17 insertions, 6 deletions
diff --git a/strings/xml.c b/strings/xml.c
index f3cfaad54fa..dee9da2864c 100644
--- a/strings/xml.c
+++ b/strings/xml.c
@@ -106,6 +106,13 @@ static void my_xml_norm_text(MY_XML_ATTR *a)
}
+static inline my_bool
+my_xml_parser_prefix_cmp(MY_XML_PARSER *p, const char *s, size_t slen)
+{
+ return (p->cur + slen > p->end) || memcmp(p->cur, s, slen);
+}
+
+
static int my_xml_scan(MY_XML_PARSER *p,MY_XML_ATTR *a)
{
int lex;
@@ -123,16 +130,20 @@ static int my_xml_scan(MY_XML_PARSER *p,MY_XML_ATTR *a)
a->beg=p->cur;
a->end=p->cur;
- if ((p->end - p->cur > 3) && !memcmp(p->cur,"<!--",4))
+ if (!my_xml_parser_prefix_cmp(p, C_STRING_WITH_LEN("<!--")))
{
- for (; (p->cur < p->end) && memcmp(p->cur, "-->", 3); p->cur++)
- {}
- if (!memcmp(p->cur, "-->", 3))
- p->cur+=3;
+ for (; p->cur < p->end; p->cur++)
+ {
+ if (!my_xml_parser_prefix_cmp(p, C_STRING_WITH_LEN("-->")))
+ {
+ p->cur+= 3;
+ break;
+ }
+ }
a->end=p->cur;
lex=MY_XML_COMMENT;
}
- else if (!memcmp(p->cur, "<![CDATA[",9))
+ else if (!my_xml_parser_prefix_cmp(p, C_STRING_WITH_LEN("<![CDATA[")))
{
p->cur+= 9;
for (; p->cur < p->end - 2 ; p->cur++)