1
0
mirror of https://gitlab.gnome.org/GNOME/libxml2.git synced 2025-10-23 01:52:48 +03:00

parser: Only check validity contraints when validating

This commit is contained in:
Nick Wellnhofer
2025-05-19 18:43:14 +02:00
parent 3a68d0b7a8
commit 47aca2c6c9
2 changed files with 31 additions and 5 deletions

15
SAX2.c
View File

@@ -39,6 +39,7 @@ xmlSAX2ErrMemory(xmlParserCtxtPtr ctxt) {
xmlCtxtErrMemory(ctxt);
}
#ifdef LIBXML_VALID_ENABLED
/**
* Handle a validation error
*
@@ -57,6 +58,7 @@ xmlErrValid(xmlParserCtxtPtr ctxt, xmlParserErrors error,
if (ctxt != NULL)
ctxt->valid = 0;
}
#endif /* LIBXML_VALID_ENABLED */
/**
* Handle a fatal parser error, i.e. violating Well-Formedness constraints
@@ -1255,9 +1257,14 @@ process_external_subset:
if (elemDecl != NULL) {
xmlAttributePtr attr = elemDecl->attributes;
#ifdef LIBXML_VALID_ENABLED
/*
* Check against defaulted attributes from the external subset
* if the document is stamped as standalone
* if the document is stamped as standalone.
*
* This should be moved to valid.c, but we don't keep track
* whether an attribute was defaulted.
*/
if ((ctxt->myDoc->standalone == 1) &&
(ctxt->myDoc->extSubset != NULL) &&
@@ -1312,6 +1319,7 @@ process_external_subset:
attr = attr->nexth;
}
}
#endif
/*
* Actually insert defaulted values when needed
@@ -1411,6 +1419,7 @@ xmlSAX1StartElement(void *ctx, const xmlChar *fullname, const xmlChar **atts)
if ((ctx == NULL) || (fullname == NULL) || (ctxt->myDoc == NULL)) return;
#ifdef LIBXML_VALID_ENABLED
/*
* First check on validity:
*/
@@ -1424,6 +1433,7 @@ xmlSAX1StartElement(void *ctx, const xmlChar *fullname, const xmlChar **atts)
"Validation failed: no DTD found !", NULL, NULL);
ctxt->validate = 0;
}
#endif
/*
* Split the full name into a namespace prefix and the tag name
@@ -2127,6 +2137,8 @@ xmlSAX2StartElementNs(void *ctx,
int i, j;
if (ctx == NULL) return;
#ifdef LIBXML_VALID_ENABLED
/*
* First check on validity:
*/
@@ -2142,6 +2154,7 @@ xmlSAX2StartElementNs(void *ctx,
"Validation failed: no DTD found !", NULL, NULL);
ctxt->validate = 0;
}
#endif /* LIBXML_VALID_ENABLED */
/*
* Take care of the rare case of an undefined namespace prefix

View File

@@ -268,6 +268,7 @@ xmlWarningMsg(xmlParserCtxtPtr ctxt, xmlParserErrors error,
str1, str2, NULL, 0, msg, str1, str2);
}
#ifdef LIBXML_VALID_ENABLED
/**
* Handle a validity error.
*
@@ -286,6 +287,7 @@ xmlValidityError(xmlParserCtxtPtr ctxt, xmlParserErrors error,
xmlCtxtErr(ctxt, NULL, XML_FROM_DTD, error, XML_ERR_ERROR,
str1, str2, NULL, 0, msg, str1, str2);
}
#endif
/**
* Handle a fatal parser error, i.e. violating Well-Formedness constraints
@@ -7234,6 +7236,7 @@ xmlHandleUndeclaredEntity(xmlParserCtxtPtr ctxt, const xmlChar *name) {
(ctxt->hasPErefs == 0))) {
xmlFatalErrMsgStr(ctxt, XML_ERR_UNDECLARED_ENTITY,
"Entity '%s' not defined\n", name);
#ifdef LIBXML_VALID_ENABLED
} else if (ctxt->validate) {
/*
* [ VC: Entity Declared ]
@@ -7244,6 +7247,7 @@ xmlHandleUndeclaredEntity(xmlParserCtxtPtr ctxt, const xmlChar *name) {
*/
xmlValidityError(ctxt, XML_ERR_UNDECLARED_ENTITY,
"Entity '%s' not defined\n", name, NULL);
#endif
} else if ((ctxt->loadsubset & ~XML_SKIP_IDS) ||
((ctxt->replaceEntities) &&
((ctxt->options & XML_PARSE_NO_XXE) == 0))) {
@@ -9092,12 +9096,21 @@ next_attr:
atts[nbatts++] = XML_INT_TO_PTR(nsIndex);
atts[nbatts++] = attr->value.name;
atts[nbatts++] = attr->valueEnd;
if ((ctxt->standalone == 1) && (attr->external != 0)) {
#ifdef LIBXML_VALID_ENABLED
/*
* This should be moved to valid.c, but we don't keep track
* whether an attribute was defaulted.
*/
if ((ctxt->validate) &&
(ctxt->standalone == 1) &&
(attr->external != 0)) {
xmlValidityError(ctxt, XML_DTD_STANDALONE_DEFAULTED,
"standalone: attribute %s on %s defaulted "
"from external subset\n",
attname, localname);
}
#endif
nbdef++;
}
}