mirror of
https://gitlab.gnome.org/GNOME/libxml2.git
synced 2025-10-24 13:33:01 +03:00
parser: Remove xmlHaltParser
Always halt the parser on resource limit and entity loop errors and remove the remaining calls which seem unnecessary.
This commit is contained in:
@@ -5173,7 +5173,6 @@ htmlParseChunk(htmlParserCtxt *ctxt, const char *chunk, int size,
|
|||||||
if (res < 0) {
|
if (res < 0) {
|
||||||
htmlParseErr(ctxt, ctxt->input->buf->error,
|
htmlParseErr(ctxt, ctxt->input->buf->error,
|
||||||
"xmlParserInputBufferPush failed", NULL, NULL);
|
"xmlParserInputBufferPush failed", NULL, NULL);
|
||||||
xmlHaltParser(ctxt);
|
|
||||||
return (ctxt->errNo);
|
return (ctxt->errNo);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
1
SAX2.c
1
SAX2.c
@@ -2513,7 +2513,6 @@ xmlSAX2Text(xmlParserCtxtPtr ctxt, const xmlChar *ch, int len,
|
|||||||
if ((len > maxSize) || (oldSize > maxSize - len)) {
|
if ((len > maxSize) || (oldSize > maxSize - len)) {
|
||||||
xmlFatalErr(ctxt, XML_ERR_RESOURCE_LIMIT,
|
xmlFatalErr(ctxt, XML_ERR_RESOURCE_LIMIT,
|
||||||
"Text node too long, try XML_PARSE_HUGE");
|
"Text node too long, try XML_PARSE_HUGE");
|
||||||
xmlHaltParser(ctxt);
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -87,8 +87,6 @@ xmlCtxtErrIO(xmlParserCtxt *ctxt, int code, const char *uri);
|
|||||||
XML_HIDDEN int
|
XML_HIDDEN int
|
||||||
xmlCtxtIsCatastrophicError(xmlParserCtxt *ctxt);
|
xmlCtxtIsCatastrophicError(xmlParserCtxt *ctxt);
|
||||||
|
|
||||||
XML_HIDDEN void
|
|
||||||
xmlHaltParser(xmlParserCtxt *ctxt);
|
|
||||||
XML_HIDDEN int
|
XML_HIDDEN int
|
||||||
xmlParserGrow(xmlParserCtxt *ctxt);
|
xmlParserGrow(xmlParserCtxt *ctxt);
|
||||||
XML_HIDDEN void
|
XML_HIDDEN void
|
||||||
|
|||||||
28
parser.c
28
parser.c
@@ -487,7 +487,6 @@ xmlParserEntityCheck(xmlParserCtxtPtr ctxt, unsigned long extra)
|
|||||||
xmlFatalErrMsg(ctxt, XML_ERR_RESOURCE_LIMIT,
|
xmlFatalErrMsg(ctxt, XML_ERR_RESOURCE_LIMIT,
|
||||||
"Maximum entity amplification factor exceeded, see "
|
"Maximum entity amplification factor exceeded, see "
|
||||||
"xmlCtxtSetMaxAmplification.\n");
|
"xmlCtxtSetMaxAmplification.\n");
|
||||||
xmlHaltParser(ctxt);
|
|
||||||
return(1);
|
return(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1928,7 +1927,6 @@ xmlCtxtPushInput(xmlParserCtxt *ctxt, xmlParserInput *value)
|
|||||||
if (newSize < 0) {
|
if (newSize < 0) {
|
||||||
xmlFatalErrMsg(ctxt, XML_ERR_RESOURCE_LIMIT,
|
xmlFatalErrMsg(ctxt, XML_ERR_RESOURCE_LIMIT,
|
||||||
"Maximum entity nesting depth exceeded");
|
"Maximum entity nesting depth exceeded");
|
||||||
xmlHaltParser(ctxt);
|
|
||||||
return(-1);
|
return(-1);
|
||||||
}
|
}
|
||||||
tmp = xmlRealloc(ctxt->inputTab, newSize * sizeof(tmp[0]));
|
tmp = xmlRealloc(ctxt->inputTab, newSize * sizeof(tmp[0]));
|
||||||
@@ -2023,7 +2021,6 @@ nodePush(xmlParserCtxt *ctxt, xmlNode *value)
|
|||||||
"Excessive depth in document: %d,"
|
"Excessive depth in document: %d,"
|
||||||
" use XML_PARSE_HUGE option\n",
|
" use XML_PARSE_HUGE option\n",
|
||||||
ctxt->nodeNr);
|
ctxt->nodeNr);
|
||||||
xmlHaltParser(ctxt);
|
|
||||||
return(-1);
|
return(-1);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -3588,7 +3585,6 @@ xmlExpandPEsInEntityValue(xmlParserCtxtPtr ctxt, xmlSBuf *buf,
|
|||||||
|
|
||||||
if (ent->flags & XML_ENT_EXPANDING) {
|
if (ent->flags & XML_ENT_EXPANDING) {
|
||||||
xmlFatalErr(ctxt, XML_ERR_ENTITY_LOOP, NULL);
|
xmlFatalErr(ctxt, XML_ERR_ENTITY_LOOP, NULL);
|
||||||
xmlHaltParser(ctxt);
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -3728,7 +3724,6 @@ xmlCheckEntityInAttValue(xmlParserCtxtPtr ctxt, xmlEntityPtr pent, int depth) {
|
|||||||
|
|
||||||
if (pent->flags & XML_ENT_EXPANDING) {
|
if (pent->flags & XML_ENT_EXPANDING) {
|
||||||
xmlFatalErr(ctxt, XML_ERR_ENTITY_LOOP, NULL);
|
xmlFatalErr(ctxt, XML_ERR_ENTITY_LOOP, NULL);
|
||||||
xmlHaltParser(ctxt);
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -3842,7 +3837,6 @@ xmlExpandEntityInAttValue(xmlParserCtxtPtr ctxt, xmlSBuf *buf,
|
|||||||
if (pent != NULL) {
|
if (pent != NULL) {
|
||||||
if (pent->flags & XML_ENT_EXPANDING) {
|
if (pent->flags & XML_ENT_EXPANDING) {
|
||||||
xmlFatalErr(ctxt, XML_ERR_ENTITY_LOOP, NULL);
|
xmlFatalErr(ctxt, XML_ERR_ENTITY_LOOP, NULL);
|
||||||
xmlHaltParser(ctxt);
|
|
||||||
return(0);
|
return(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -5612,7 +5606,6 @@ xmlParseEntityDecl(xmlParserCtxt *ctxt) {
|
|||||||
if (RAW != '>') {
|
if (RAW != '>') {
|
||||||
xmlFatalErrMsgStr(ctxt, XML_ERR_ENTITY_NOT_FINISHED,
|
xmlFatalErrMsgStr(ctxt, XML_ERR_ENTITY_NOT_FINISHED,
|
||||||
"xmlParseEntityDecl: entity %s not terminated\n", name);
|
"xmlParseEntityDecl: entity %s not terminated\n", name);
|
||||||
xmlHaltParser(ctxt);
|
|
||||||
} else {
|
} else {
|
||||||
#ifdef LIBXML_VALID_ENABLED
|
#ifdef LIBXML_VALID_ENABLED
|
||||||
if ((ctxt->validate) && (ctxt->inputNr > oldInputNr)) {
|
if ((ctxt->validate) && (ctxt->inputNr > oldInputNr)) {
|
||||||
@@ -7672,7 +7665,6 @@ xmlParsePERefInternal(xmlParserCtxt *ctxt, int markupDecl) {
|
|||||||
|
|
||||||
if (entity->flags & XML_ENT_EXPANDING) {
|
if (entity->flags & XML_ENT_EXPANDING) {
|
||||||
xmlFatalErr(ctxt, XML_ERR_ENTITY_LOOP, NULL);
|
xmlFatalErr(ctxt, XML_ERR_ENTITY_LOOP, NULL);
|
||||||
xmlHaltParser(ctxt);
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -9736,7 +9728,6 @@ xmlParseElementStart(xmlParserCtxtPtr ctxt) {
|
|||||||
xmlFatalErrMsgInt(ctxt, XML_ERR_RESOURCE_LIMIT,
|
xmlFatalErrMsgInt(ctxt, XML_ERR_RESOURCE_LIMIT,
|
||||||
"Excessive depth in document: %d use XML_PARSE_HUGE option\n",
|
"Excessive depth in document: %d use XML_PARSE_HUGE option\n",
|
||||||
ctxt->nameNr);
|
ctxt->nameNr);
|
||||||
xmlHaltParser(ctxt);
|
|
||||||
return(-1);
|
return(-1);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -11296,7 +11287,6 @@ xmlParseChunk(xmlParserCtxt *ctxt, const char *chunk, int size,
|
|||||||
xmlBufUpdateInput(ctxt->input->buf->buffer, ctxt->input, pos);
|
xmlBufUpdateInput(ctxt->input->buf->buffer, ctxt->input, pos);
|
||||||
if (res < 0) {
|
if (res < 0) {
|
||||||
xmlCtxtErrIO(ctxt, ctxt->input->buf->error, NULL);
|
xmlCtxtErrIO(ctxt, ctxt->input->buf->error, NULL);
|
||||||
xmlHaltParser(ctxt);
|
|
||||||
return(ctxt->errNo);
|
return(ctxt->errNo);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -11309,7 +11299,6 @@ xmlParseChunk(xmlParserCtxt *ctxt, const char *chunk, int size,
|
|||||||
if (curBase > maxLength) {
|
if (curBase > maxLength) {
|
||||||
xmlFatalErr(ctxt, XML_ERR_RESOURCE_LIMIT,
|
xmlFatalErr(ctxt, XML_ERR_RESOURCE_LIMIT,
|
||||||
"Buffer size limit exceeded, try XML_PARSE_HUGE\n");
|
"Buffer size limit exceeded, try XML_PARSE_HUGE\n");
|
||||||
xmlHaltParser(ctxt);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if ((ctxt->errNo != XML_ERR_OK) && (ctxt->disableSAX != 0))
|
if ((ctxt->errNo != XML_ERR_OK) && (ctxt->disableSAX != 0))
|
||||||
@@ -11321,7 +11310,6 @@ xmlParseChunk(xmlParserCtxt *ctxt, const char *chunk, int size,
|
|||||||
xmlBufUpdateInput(ctxt->input->buf->buffer, ctxt->input, pos);
|
xmlBufUpdateInput(ctxt->input->buf->buffer, ctxt->input, pos);
|
||||||
if (res < 0) {
|
if (res < 0) {
|
||||||
xmlCtxtErrIO(ctxt, ctxt->input->buf->error, NULL);
|
xmlCtxtErrIO(ctxt, ctxt->input->buf->error, NULL);
|
||||||
xmlHaltParser(ctxt);
|
|
||||||
return(ctxt->errNo);
|
return(ctxt->errNo);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -11421,12 +11409,21 @@ void
|
|||||||
xmlStopParser(xmlParserCtxt *ctxt) {
|
xmlStopParser(xmlParserCtxt *ctxt) {
|
||||||
if (ctxt == NULL)
|
if (ctxt == NULL)
|
||||||
return;
|
return;
|
||||||
xmlHaltParser(ctxt);
|
|
||||||
|
/* This stops the parser */
|
||||||
|
ctxt->disableSAX = 2;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* TODO: Update ctxt->lastError and ctxt->wellFormed?
|
* xmlStopParser is often called from error handlers,
|
||||||
|
* so we can't raise an error here to avoid infinite
|
||||||
|
* loops. Just make sure that an error condition is
|
||||||
|
* reported.
|
||||||
*/
|
*/
|
||||||
if (ctxt->errNo != XML_ERR_NO_MEMORY)
|
if (ctxt->errNo == XML_ERR_OK) {
|
||||||
ctxt->errNo = XML_ERR_USER_STOP;
|
ctxt->errNo = XML_ERR_USER_STOP;
|
||||||
|
ctxt->lastError.code = XML_ERR_USER_STOP;
|
||||||
|
ctxt->wellFormed = 0;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -11795,7 +11792,6 @@ xmlCtxtParseEntity(xmlParserCtxtPtr ctxt, xmlEntityPtr ent) {
|
|||||||
*/
|
*/
|
||||||
if (ent->flags & XML_ENT_EXPANDING) {
|
if (ent->flags & XML_ENT_EXPANDING) {
|
||||||
xmlFatalErr(ctxt, XML_ERR_ENTITY_LOOP, NULL);
|
xmlFatalErr(ctxt, XML_ERR_ENTITY_LOOP, NULL);
|
||||||
xmlHaltParser(ctxt);
|
|
||||||
goto error;
|
goto error;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -390,8 +390,18 @@ xmlCtxtVErr(xmlParserCtxt *ctxt, xmlNode *node, xmlErrorDomain domain,
|
|||||||
if (level == XML_ERR_FATAL) {
|
if (level == XML_ERR_FATAL) {
|
||||||
ctxt->wellFormed = 0;
|
ctxt->wellFormed = 0;
|
||||||
|
|
||||||
if (xmlCtxtIsCatastrophicError(ctxt))
|
/*
|
||||||
ctxt->disableSAX = 2; /* stop parser */
|
* By long-standing design, the parser isn't completely
|
||||||
|
* stopped on well-formedness errors. Only SAX callbacks
|
||||||
|
* are disabled.
|
||||||
|
*
|
||||||
|
* In some situations, we really want to abort as fast
|
||||||
|
* as possible.
|
||||||
|
*/
|
||||||
|
if (xmlCtxtIsCatastrophicError(ctxt) ||
|
||||||
|
code == XML_ERR_RESOURCE_LIMIT ||
|
||||||
|
code == XML_ERR_ENTITY_LOOP)
|
||||||
|
ctxt->disableSAX = 2; /* really stop parser */
|
||||||
else if (ctxt->recovery == 0)
|
else if (ctxt->recovery == 0)
|
||||||
ctxt->disableSAX = 1;
|
ctxt->disableSAX = 1;
|
||||||
}
|
}
|
||||||
@@ -520,20 +530,6 @@ xmlIsLetter(int c) {
|
|||||||
/* we need to keep enough input to show errors in context */
|
/* we need to keep enough input to show errors in context */
|
||||||
#define LINE_LEN 80
|
#define LINE_LEN 80
|
||||||
|
|
||||||
/**
|
|
||||||
* Blocks further parser processing don't override error
|
|
||||||
* for internal use
|
|
||||||
*
|
|
||||||
* @param ctxt an XML parser context
|
|
||||||
*/
|
|
||||||
void
|
|
||||||
xmlHaltParser(xmlParserCtxt *ctxt) {
|
|
||||||
if (ctxt == NULL)
|
|
||||||
return;
|
|
||||||
ctxt->instate = XML_PARSER_EOF; /* TODO: Remove after refactoring */
|
|
||||||
ctxt->disableSAX = 2;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @deprecated This function was internal and is deprecated.
|
* @deprecated This function was internal and is deprecated.
|
||||||
*
|
*
|
||||||
@@ -577,7 +573,6 @@ xmlParserGrow(xmlParserCtxt *ctxt) {
|
|||||||
if (curBase > maxLength) {
|
if (curBase > maxLength) {
|
||||||
xmlFatalErr(ctxt, XML_ERR_RESOURCE_LIMIT,
|
xmlFatalErr(ctxt, XML_ERR_RESOURCE_LIMIT,
|
||||||
"Buffer size limit exceeded, try XML_PARSE_HUGE\n");
|
"Buffer size limit exceeded, try XML_PARSE_HUGE\n");
|
||||||
xmlHaltParser(ctxt);
|
|
||||||
return(-1);
|
return(-1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user