From e8fb3d639fd5a0a1f288b0e988744c5be2007328 Mon Sep 17 00:00:00 2001 From: Nick Wellnhofer Date: Tue, 2 Jan 2024 17:45:54 +0100 Subject: [PATCH] parser: Convert some "internal errors" to meaningful codes --- error.c | 3 +++ include/libxml/xmlerror.h | 1 + parser.c | 28 ++++++---------------------- python/tests/reader2.py | 6 ++---- result/errors/754946.xml.ent | 3 +-- result/errors/754946.xml.err | 3 +-- result/errors/754946.xml.str | 3 +-- result/errors/759573-2.xml.ent | 3 +-- result/errors/759573-2.xml.err | 3 +-- result/errors/759573-2.xml.str | 3 +-- result/errors/759573.xml.ent | 3 +-- result/errors/759573.xml.err | 3 +-- result/errors/759573.xml.str | 3 +-- result/errors/content1.xml.ent | 3 +-- result/errors/content1.xml.err | 3 +-- result/errors/content1.xml.str | 3 +-- result/errors10/781205.xml.err | 3 +-- result/errors10/781361.xml.err | 3 +-- result/valid/t8.xml.err | 3 +-- result/valid/t8.xml.err.rdr | 3 +-- result/valid/t8a.xml.err | 3 +-- result/valid/t8a.xml.err.rdr | 3 +-- xinclude.c | 2 +- 23 files changed, 31 insertions(+), 63 deletions(-) diff --git a/error.c b/error.c index a68451e4..bef92937 100644 --- a/error.c +++ b/error.c @@ -1085,6 +1085,9 @@ xmlErrString(xmlParserErrors code) { case XML_ERR_CONDSEC_INVALID: errmsg = "XML conditional section '[' expected"; break; + case XML_ERR_INT_SUBSET_NOT_FINISHED: + errmsg = "Content error in the internal subset"; + break; case XML_ERR_EXT_SUBSET_NOT_FINISHED: errmsg = "Content error in the external subset"; break; diff --git a/include/libxml/xmlerror.h b/include/libxml/xmlerror.h index 0be0b885..6dc1bd04 100644 --- a/include/libxml/xmlerror.h +++ b/include/libxml/xmlerror.h @@ -215,6 +215,7 @@ typedef enum { XML_ERR_ARGUMENT, /* 115 */ XML_ERR_SYSTEM, /* 116 */ XML_ERR_REDECL_PREDEF_ENTITY, /* 117 */ + XML_ERR_INT_SUBSET_NOT_FINISHED, /* 118 */ XML_NS_ERR_XML_NAMESPACE = 200, XML_NS_ERR_UNDEFINED_NAMESPACE, /* 201 */ XML_NS_ERR_QNAME, /* 202 */ diff --git a/parser.c b/parser.c index 66475b47..03ccfc21 100644 --- a/parser.c +++ b/parser.c @@ -7889,18 +7889,15 @@ xmlLoadEntityContent(xmlParserCtxtPtr ctxt, xmlEntityPtr entity) { ((entity->etype != XML_EXTERNAL_PARAMETER_ENTITY) && (entity->etype != XML_EXTERNAL_GENERAL_PARSED_ENTITY)) || (entity->content != NULL)) { - xmlFatalErr(ctxt, XML_ERR_INTERNAL_ERROR, + xmlFatalErr(ctxt, XML_ERR_ARGUMENT, "xmlLoadEntityContent parameter error"); return(-1); } input = xmlLoadExternalEntity((char *) entity->URI, (char *) entity->ExternalID, ctxt); - if (input == NULL) { - xmlFatalErr(ctxt, XML_ERR_INTERNAL_ERROR, - "xmlLoadEntityContent input error"); + if (input == NULL) return(-1); - } oldinput = ctxt->input; oldinputNr = ctxt->inputNr; @@ -8221,9 +8218,7 @@ xmlParseInternalSubset(xmlParserCtxtPtr ctxt) { } else if (RAW == '%') { xmlParsePEReference(ctxt); } else { - xmlFatalErr(ctxt, XML_ERR_INTERNAL_ERROR, - "xmlParseInternalSubset: error detected in" - " Markup declaration\n"); + xmlFatalErr(ctxt, XML_ERR_INT_SUBSET_NOT_FINISHED, NULL); xmlHaltParser(ctxt); return; } @@ -8404,11 +8399,8 @@ xmlParseStartTag(xmlParserCtxtPtr ctxt) { ((RAW != '/') || (NXT(1) != '>')) && (IS_BYTE_CHAR(RAW))) && (PARSER_STOPPED(ctxt) == 0)) { attname = xmlParseAttribute(ctxt, &attvalue); - if (attname == NULL) { - xmlFatalErrMsg(ctxt, XML_ERR_INTERNAL_ERROR, - "xmlParseStartTag: problem parsing attributes\n"); + if (attname == NULL) break; - } if (attvalue != NULL) { /* * [ WFC: Unique Att Spec ] @@ -8939,14 +8931,13 @@ xmlParseStartTag2(xmlParserCtxtPtr ctxt, const xmlChar **pref, const xmlChar **atts = ctxt->atts; unsigned attrHashSize = 0; int maxatts = ctxt->maxatts; - int nratts, nbatts, nbdef, inputid; + int nratts, nbatts, nbdef; int i, j, nbNs, nbTotalDef, attval, nsIndex, maxAtts; int alloc = 0; if (RAW != '<') return(NULL); NEXT1; - inputid = ctxt->input->id; nbatts = 0; nratts = 0; nbdef = 0; @@ -9188,13 +9179,6 @@ next_attr: GROW; } - if (ctxt->input->id != inputid) { - xmlFatalErr(ctxt, XML_ERR_INTERNAL_ERROR, - "Unexpected change of input\n"); - localname = NULL; - goto done; - } - /* * Namespaces from default attributes */ @@ -12282,7 +12266,7 @@ xmlParseInNodeContext(xmlNodePtr node, const char *data, int datalen, * check all input parameters, grab the document */ if ((lst == NULL) || (node == NULL) || (data == NULL) || (datalen < 0)) - return(XML_ERR_INTERNAL_ERROR); + return(XML_ERR_ARGUMENT); switch (node->type) { case XML_ELEMENT_NODE: case XML_ATTRIBUTE_NODE: diff --git a/python/tests/reader2.py b/python/tests/reader2.py index dbe061e7..59141a88 100755 --- a/python/tests/reader2.py +++ b/python/tests/reader2.py @@ -63,8 +63,7 @@ Entity: line 1: ^ """.format(dir_prefix), 't8': -"""{0}/t8.xml:6: parser error : internal error: xmlParseInternalSubset: error detected in Markup declaration - +"""{0}/t8.xml:6: parser error : Content error in the internal subset %defroot; %defmiddle; %deftest; ^ Entity: line 1: @@ -72,8 +71,7 @@ Entity: line 1: ^ """.format(dir_prefix), 't8a': -"""{0}/t8a.xml:6: parser error : internal error: xmlParseInternalSubset: error detected in Markup declaration - +"""{0}/t8a.xml:6: parser error : Content error in the internal subset %defroot;%defmiddle;%deftest; ^ Entity: line 1: diff --git a/result/errors/754946.xml.ent b/result/errors/754946.xml.ent index 7dc0bb01..22951f87 100644 --- a/result/errors/754946.xml.ent +++ b/result/errors/754946.xml.ent @@ -1,5 +1,4 @@ -./test/errors/754946.xml:3: parser error : internal error: xmlParseInternalSubset: error detected in Markup declaration - +./test/errors/754946.xml:3: parser error : Content error in the internal subset %SYSTEM; ^ Entity: line 1: diff --git a/result/errors/754946.xml.err b/result/errors/754946.xml.err index 7dc0bb01..22951f87 100644 --- a/result/errors/754946.xml.err +++ b/result/errors/754946.xml.err @@ -1,5 +1,4 @@ -./test/errors/754946.xml:3: parser error : internal error: xmlParseInternalSubset: error detected in Markup declaration - +./test/errors/754946.xml:3: parser error : Content error in the internal subset %SYSTEM; ^ Entity: line 1: diff --git a/result/errors/754946.xml.str b/result/errors/754946.xml.str index 5d6a8b28..6c4d253f 100644 --- a/result/errors/754946.xml.str +++ b/result/errors/754946.xml.str @@ -1,5 +1,4 @@ -./test/errors/754946.xml:3: parser error : internal error: xmlParseInternalSubset: error detected in Markup declaration - +./test/errors/754946.xml:3: parser error : Content error in the internal subset %SYSTEM; ^ Entity: line 1: diff --git a/result/errors/759573-2.xml.ent b/result/errors/759573-2.xml.ent index 01c81576..ea2e421a 100644 --- a/result/errors/759573-2.xml.ent +++ b/result/errors/759573-2.xml.ent @@ -16,8 +16,7 @@ Entity: line 1: parser error : ParsePI: PI xDOCTYPEm space expected Entity: line 1: ^ -./test/errors/759573-2.xml:6: parser error : internal error: xmlParseInternalSubset: error detected in Markup declaration - +./test/errors/759573-2.xml:6: parser error : Content error in the internal subset %xx; ^ Entity: line 2: diff --git a/result/errors/759573-2.xml.err b/result/errors/759573-2.xml.err index 01c81576..ea2e421a 100644 --- a/result/errors/759573-2.xml.err +++ b/result/errors/759573-2.xml.err @@ -16,8 +16,7 @@ Entity: line 1: parser error : ParsePI: PI xDOCTYPEm space expected Entity: line 1: ^ -./test/errors/759573-2.xml:6: parser error : internal error: xmlParseInternalSubset: error detected in Markup declaration - +./test/errors/759573-2.xml:6: parser error : Content error in the internal subset %xx; ^ Entity: line 2: diff --git a/result/errors/759573-2.xml.str b/result/errors/759573-2.xml.str index 39f77a66..67f31b6e 100644 --- a/result/errors/759573-2.xml.str +++ b/result/errors/759573-2.xml.str @@ -16,8 +16,7 @@ Entity: line 1: parser error : ParsePI: PI xDOCTYPEm space expected Entity: line 1: ^ -./test/errors/759573-2.xml:6: parser error : internal error: xmlParseInternalSubset: error detected in Markup declaration - +./test/errors/759573-2.xml:6: parser error : Content error in the internal subset %xx; ^ Entity: line 2: diff --git a/result/errors/759573.xml.ent b/result/errors/759573.xml.ent index 74322b66..3c6be9a8 100644 --- a/result/errors/759573.xml.ent +++ b/result/errors/759573.xml.ent @@ -13,8 +13,7 @@ T t (A)>%xx; Entity: line 1: %%xx; ^ Entity: line 1: diff --git a/result/errors/759573.xml.err b/result/errors/759573.xml.err index 74322b66..3c6be9a8 100644 --- a/result/errors/759573.xml.err +++ b/result/errors/759573.xml.err @@ -13,8 +13,7 @@ T t (A)>%xx; Entity: line 1: %%xx; ^ Entity: line 1: diff --git a/result/errors/759573.xml.str b/result/errors/759573.xml.str index 37df762d..2736393b 100644 --- a/result/errors/759573.xml.str +++ b/result/errors/759573.xml.str @@ -13,8 +13,7 @@ T t (A)>%xx; Entity: line 1: %%xx; ^ Entity: line 1: diff --git a/result/errors/content1.xml.ent b/result/errors/content1.xml.ent index 64511571..6e361d6a 100644 --- a/result/errors/content1.xml.ent +++ b/result/errors/content1.xml.ent @@ -4,7 +4,6 @@ ./test/errors/content1.xml:7: parser error : expected '>' ^ -./test/errors/content1.xml:7: parser error : internal error: xmlParseInternalSubset: error detected in Markup declaration - +./test/errors/content1.xml:7: parser error : Content error in the internal subset ^ diff --git a/result/errors/content1.xml.err b/result/errors/content1.xml.err index 64511571..6e361d6a 100644 --- a/result/errors/content1.xml.err +++ b/result/errors/content1.xml.err @@ -4,7 +4,6 @@ ./test/errors/content1.xml:7: parser error : expected '>' ^ -./test/errors/content1.xml:7: parser error : internal error: xmlParseInternalSubset: error detected in Markup declaration - +./test/errors/content1.xml:7: parser error : Content error in the internal subset ^ diff --git a/result/errors/content1.xml.str b/result/errors/content1.xml.str index 47a6b6f8..64b532c2 100644 --- a/result/errors/content1.xml.str +++ b/result/errors/content1.xml.str @@ -4,8 +4,7 @@ ./test/errors/content1.xml:7: parser error : expected '>' ^ -./test/errors/content1.xml:7: parser error : internal error: xmlParseInternalSubset: error detected in Markup declaration - +./test/errors/content1.xml:7: parser error : Content error in the internal subset ^ ./test/errors/content1.xml : failed to parse diff --git a/result/errors10/781205.xml.err b/result/errors10/781205.xml.err index f4e0892d..c9cb96c0 100644 --- a/result/errors10/781205.xml.err +++ b/result/errors10/781205.xml.err @@ -1,5 +1,4 @@ -./test/errors10/781205.xml:3: parser error : internal error: xmlParseInternalSubset: error detected in Markup declaration - +./test/errors10/781205.xml:3: parser error : Content error in the internal subset %a; ^ Entity: line 1: diff --git a/result/errors10/781361.xml.err b/result/errors10/781361.xml.err index 6153cc9a..7bbace59 100644 --- a/result/errors10/781361.xml.err +++ b/result/errors10/781361.xml.err @@ -1,7 +1,6 @@ ./test/errors10/781361.xml:4: parser error : xmlParseElementDecl: 'EMPTY', 'ANY' or '(' expected ^ -./test/errors10/781361.xml:4: parser error : internal error: xmlParseInternalSubset: error detected in Markup declaration - +./test/errors10/781361.xml:4: parser error : Content error in the internal subset ^ diff --git a/result/valid/t8.xml.err b/result/valid/t8.xml.err index 8f874179..983e4359 100644 --- a/result/valid/t8.xml.err +++ b/result/valid/t8.xml.err @@ -1,5 +1,4 @@ -./test/valid/t8.xml:6: parser error : internal error: xmlParseInternalSubset: error detected in Markup declaration - +./test/valid/t8.xml:6: parser error : Content error in the internal subset %defroot; %defmiddle; %deftest; ^ Entity: line 1: diff --git a/result/valid/t8.xml.err.rdr b/result/valid/t8.xml.err.rdr index 06b7baf7..7d06fd1f 100644 --- a/result/valid/t8.xml.err.rdr +++ b/result/valid/t8.xml.err.rdr @@ -1,5 +1,4 @@ -./test/valid/t8.xml:6: parser error : internal error: xmlParseInternalSubset: error detected in Markup declaration - +./test/valid/t8.xml:6: parser error : Content error in the internal subset %defroot; %defmiddle; %deftest; ^ Entity: line 1: diff --git a/result/valid/t8a.xml.err b/result/valid/t8a.xml.err index 211e9e86..f4994bd8 100644 --- a/result/valid/t8a.xml.err +++ b/result/valid/t8a.xml.err @@ -1,5 +1,4 @@ -./test/valid/t8a.xml:6: parser error : internal error: xmlParseInternalSubset: error detected in Markup declaration - +./test/valid/t8a.xml:6: parser error : Content error in the internal subset %defroot;%defmiddle;%deftest; ^ Entity: line 1: diff --git a/result/valid/t8a.xml.err.rdr b/result/valid/t8a.xml.err.rdr index 2ae90c90..8deb8245 100644 --- a/result/valid/t8a.xml.err.rdr +++ b/result/valid/t8a.xml.err.rdr @@ -1,5 +1,4 @@ -./test/valid/t8a.xml:6: parser error : internal error: xmlParseInternalSubset: error detected in Markup declaration - +./test/valid/t8a.xml:6: parser error : Content error in the internal subset %defroot;%defmiddle;%deftest; ^ Entity: line 1: diff --git a/xinclude.c b/xinclude.c index 72a88c99..05cb0034 100644 --- a/xinclude.c +++ b/xinclude.c @@ -2193,7 +2193,7 @@ xmlXIncludeDoProcessRoot(xmlXIncludeCtxtPtr ctxt, xmlNodePtr tree) { int xmlXIncludeGetLastError(xmlXIncludeCtxtPtr ctxt) { if (ctxt == NULL) - return(XML_ERR_INTERNAL_ERROR); + return(XML_ERR_ARGUMENT); return(ctxt->errNo); }