mirror of
https://gitlab.gnome.org/GNOME/libxml2.git
synced 2025-10-26 00:37:43 +03:00
Fix handling of unexpected EOF in xmlParseContent
Readd the XML_ERR_TAG_NOT_FINISHED error on unexpected EOF which was
removed in commit 62150ed2.
This commit also introduced a regression for direct users of
xmlParseContent. Unclosed tags weren't checked.
This commit is contained in:
48
parser.c
48
parser.c
@@ -9837,16 +9837,15 @@ xmlParseCDSect(xmlParserCtxtPtr ctxt) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* xmlParseContent:
|
* xmlParseContentInternal:
|
||||||
* @ctxt: an XML parser context
|
* @ctxt: an XML parser context
|
||||||
*
|
*
|
||||||
* Parse a content:
|
* Parse a content sequence. Stops at EOF or '</'. Leaves checking of
|
||||||
*
|
* unexpected EOF to the caller.
|
||||||
* [43] content ::= (element | CharData | Reference | CDSect | PI | Comment)*
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
void
|
static void
|
||||||
xmlParseContent(xmlParserCtxtPtr ctxt) {
|
xmlParseContentInternal(xmlParserCtxtPtr ctxt) {
|
||||||
int nameNr = ctxt->nameNr;
|
int nameNr = ctxt->nameNr;
|
||||||
|
|
||||||
GROW;
|
GROW;
|
||||||
@@ -9921,6 +9920,30 @@ xmlParseContent(xmlParserCtxtPtr ctxt) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* xmlParseContent:
|
||||||
|
* @ctxt: an XML parser context
|
||||||
|
*
|
||||||
|
* Parse a content sequence. Stops at EOF or '</'.
|
||||||
|
*
|
||||||
|
* [43] content ::= (element | CharData | Reference | CDSect | PI | Comment)*
|
||||||
|
*/
|
||||||
|
|
||||||
|
void
|
||||||
|
xmlParseContent(xmlParserCtxtPtr ctxt) {
|
||||||
|
int nameNr = ctxt->nameNr;
|
||||||
|
|
||||||
|
xmlParseContentInternal(ctxt);
|
||||||
|
|
||||||
|
if ((ctxt->instate != XML_PARSER_EOF) && (ctxt->nameNr > nameNr)) {
|
||||||
|
const xmlChar *name = ctxt->nameTab[ctxt->nameNr - 1];
|
||||||
|
int line = (ptrdiff_t) ctxt->pushTab[ctxt->nameNr * 4 - 2];
|
||||||
|
xmlFatalErrMsgStrIntStr(ctxt, XML_ERR_TAG_NOT_FINISHED,
|
||||||
|
"Premature end of data in tag %s line %d\n",
|
||||||
|
name, line, NULL);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* xmlParseElement:
|
* xmlParseElement:
|
||||||
* @ctxt: an XML parser context
|
* @ctxt: an XML parser context
|
||||||
@@ -9939,9 +9962,20 @@ void
|
|||||||
xmlParseElement(xmlParserCtxtPtr ctxt) {
|
xmlParseElement(xmlParserCtxtPtr ctxt) {
|
||||||
if (xmlParseElementStart(ctxt) != 0)
|
if (xmlParseElementStart(ctxt) != 0)
|
||||||
return;
|
return;
|
||||||
xmlParseContent(ctxt);
|
|
||||||
|
xmlParseContentInternal(ctxt);
|
||||||
if (ctxt->instate == XML_PARSER_EOF)
|
if (ctxt->instate == XML_PARSER_EOF)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
if (CUR == 0) {
|
||||||
|
const xmlChar *name = ctxt->nameTab[ctxt->nameNr - 1];
|
||||||
|
int line = (ptrdiff_t) ctxt->pushTab[ctxt->nameNr * 4 - 2];
|
||||||
|
xmlFatalErrMsgStrIntStr(ctxt, XML_ERR_TAG_NOT_FINISHED,
|
||||||
|
"Premature end of data in tag %s line %d\n",
|
||||||
|
name, line, NULL);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
xmlParseElementEnd(ctxt);
|
xmlParseElementEnd(ctxt);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -71,8 +71,8 @@ class TestCase(unittest.TestCase):
|
|||||||
(s,len(s),"dummy.xml",None,0),
|
(s,len(s),"dummy.xml",None,0),
|
||||||
libxml2.treeError,
|
libxml2.treeError,
|
||||||
domain=libxml2.XML_FROM_PARSER,
|
domain=libxml2.XML_FROM_PARSER,
|
||||||
code=libxml2.XML_ERR_LTSLASH_REQUIRED,
|
code=libxml2.XML_ERR_TAG_NOT_FINISHED,
|
||||||
message='EndTag: \'</\' not found\n',
|
message='Premature end of data in tag x line 1\n',
|
||||||
level=libxml2.XML_ERR_FATAL,
|
level=libxml2.XML_ERR_FATAL,
|
||||||
file='dummy.xml',
|
file='dummy.xml',
|
||||||
line=3)
|
line=3)
|
||||||
|
|||||||
@@ -2,6 +2,6 @@
|
|||||||
Bytes: 0xEE 0x5D 0x5D 0x3E
|
Bytes: 0xEE 0x5D 0x5D 0x3E
|
||||||
<d><![CDATA[0000000000000<30>]]>
|
<d><![CDATA[0000000000000<30>]]>
|
||||||
^
|
^
|
||||||
./test/errors/754947.xml:1: parser error : EndTag: '</' not found
|
./test/errors/754947.xml:1: parser error : Premature end of data in tag d line 1
|
||||||
<d><![CDATA[0000000000000<30>]]>
|
<d><![CDATA[0000000000000<30>]]>
|
||||||
^
|
^
|
||||||
|
|||||||
@@ -2,6 +2,6 @@
|
|||||||
Bytes: 0xEE 0x5D 0x5D 0x3E
|
Bytes: 0xEE 0x5D 0x5D 0x3E
|
||||||
<d><![CDATA[0000000000000<30>]]>
|
<d><![CDATA[0000000000000<30>]]>
|
||||||
^
|
^
|
||||||
./test/errors/754947.xml:1: parser error : EndTag: '</' not found
|
./test/errors/754947.xml:1: parser error : Premature end of data in tag d line 1
|
||||||
<d><![CDATA[0000000000000<30>]]>
|
<d><![CDATA[0000000000000<30>]]>
|
||||||
^
|
^
|
||||||
|
|||||||
Reference in New Issue
Block a user