diff options
author | bar@mysql.com <> | 2006-04-17 14:40:25 +0500 |
---|---|---|
committer | bar@mysql.com <> | 2006-04-17 14:40:25 +0500 |
commit | 8fb685c254fb7eac0a87d79132a2a72415d86397 (patch) | |
tree | ad61da58fe13bee1f57a91497b08bc491cec4c3d /strings/xml.c | |
parent | 6f5999e9b5ffa775e8d3c0510e8b2c6a6ef2b1e7 (diff) | |
download | mariadb-git-8fb685c254fb7eac0a87d79132a2a72415d86397.tar.gz |
Bug#18201: XML: ExtractValue works even if the xml
fragment is not well-formed xml
Problem:
- ExtractValue silently returned NULL if a wrong XML value is passed.
- In some cases "unexpected END-OF-INPUT" error was not detected, and
a non-NULL result could be returned for a bad XML value.
Fix:
- Adding warning messages, to make user aware why NULL was returned.
- Missing "unexpected END-OF-INPUT" error is reported now.
Diffstat (limited to 'strings/xml.c')
-rw-r--r-- | strings/xml.c | 27 |
1 files changed, 19 insertions, 8 deletions
diff --git a/strings/xml.c b/strings/xml.c index 4c09e85604d..76fdd07f25e 100644 --- a/strings/xml.c +++ b/strings/xml.c @@ -43,7 +43,7 @@ static const char *lex2str(int lex) { switch(lex) { - case MY_XML_EOF: return "EOF"; + case MY_XML_EOF: return "END-OF-INPUT"; case MY_XML_STRING: return "STRING"; case MY_XML_IDENT: return "IDENT"; case MY_XML_CDATA: return "CDATA"; @@ -195,8 +195,13 @@ static int my_xml_leave(MY_XML_PARSER *p, const char *str, uint slen) if (str && (slen != glen)) { mstr(s,str,sizeof(s)-1,slen); - mstr(g,e+1,sizeof(g)-1,glen), - sprintf(p->errstr,"'</%s>' unexpected ('</%s>' wanted)",s,g); + if (glen) + { + mstr(g,e+1,sizeof(g)-1,glen), + sprintf(p->errstr,"'</%s>' unexpected ('</%s>' wanted)",s,g); + } + else + sprintf(p->errstr,"'</%s>' unexpected (END-OF-INPUT wanted)", s); return MY_XML_ERROR; } @@ -247,7 +252,7 @@ int my_xml_parse(MY_XML_PARSER *p,const char *str, uint len) { if (MY_XML_IDENT != (lex=my_xml_scan(p,&a))) { - sprintf(p->errstr,"1: %s unexpected (ident wanted)",lex2str(lex)); + sprintf(p->errstr,"%s unexpected (ident wanted)",lex2str(lex)); return MY_XML_ERROR; } if (MY_XML_OK != my_xml_leave(p,a.beg,(uint) (a.end-a.beg))) @@ -275,7 +280,7 @@ int my_xml_parse(MY_XML_PARSER *p,const char *str, uint len) } else { - sprintf(p->errstr,"3: %s unexpected (ident or '/' wanted)", + sprintf(p->errstr,"%s unexpected (ident or '/' wanted)", lex2str(lex)); return MY_XML_ERROR; } @@ -297,7 +302,7 @@ int my_xml_parse(MY_XML_PARSER *p,const char *str, uint len) } else { - sprintf(p->errstr,"4: %s unexpected (ident or string wanted)", + sprintf(p->errstr,"%s unexpected (ident or string wanted)", lex2str(lex)); return MY_XML_ERROR; } @@ -325,7 +330,7 @@ gt: { if (lex != MY_XML_QUESTION) { - sprintf(p->errstr,"6: %s unexpected ('?' wanted)",lex2str(lex)); + sprintf(p->errstr,"%s unexpected ('?' wanted)",lex2str(lex)); return MY_XML_ERROR; } if (MY_XML_OK != my_xml_leave(p,NULL,0)) @@ -341,7 +346,7 @@ gt: if (lex != MY_XML_GT) { - sprintf(p->errstr,"5: %s unexpected ('>' wanted)",lex2str(lex)); + sprintf(p->errstr,"%s unexpected ('>' wanted)",lex2str(lex)); return MY_XML_ERROR; } } @@ -359,6 +364,12 @@ gt: } } } + + if (p->attr[0]) + { + sprintf(p->errstr,"unexpected END-OF-INPUT"); + return MY_XML_ERROR; + } return MY_XML_OK; } |