mirror of
https://gitlab.gnome.org/GNOME/libxml2.git
synced 2025-10-23 01:52:48 +03:00
valid: Eliminate xmlCtxtGetDtdElementDesc
Improves malloca failure reporting without parser context.
This commit is contained in:
133
valid.c
133
valid.c
@@ -3244,41 +3244,6 @@ xmlValidNormalizeString(xmlChar *str) {
|
|||||||
*dst = 0;
|
*dst = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* xmlCtxtGetDtdElementDesc:
|
|
||||||
* @ctxt: validation context
|
|
||||||
* @dtd: a pointer to the DtD to search
|
|
||||||
* @name: the element name
|
|
||||||
*
|
|
||||||
* Search the DTD for the description of this element
|
|
||||||
*
|
|
||||||
* returns the xmlElementPtr if found or NULL
|
|
||||||
*/
|
|
||||||
|
|
||||||
static xmlElementPtr
|
|
||||||
xmlCtxtGetDtdElementDesc(xmlValidCtxtPtr ctxt, xmlDtdPtr dtd,
|
|
||||||
const xmlChar *name) {
|
|
||||||
xmlElementTablePtr table;
|
|
||||||
xmlElementPtr cur;
|
|
||||||
const xmlChar *localName;
|
|
||||||
xmlChar *prefix;
|
|
||||||
|
|
||||||
if ((dtd == NULL) || (name == NULL)) return(NULL);
|
|
||||||
if (dtd->elements == NULL)
|
|
||||||
return(NULL);
|
|
||||||
table = (xmlElementTablePtr) dtd->elements;
|
|
||||||
|
|
||||||
localName = xmlSplitQName4(name, &prefix);
|
|
||||||
if (localName == NULL) {
|
|
||||||
xmlVErrMemory(ctxt);
|
|
||||||
return(NULL);
|
|
||||||
}
|
|
||||||
cur = xmlHashLookup2(table, localName, prefix);
|
|
||||||
if (prefix != NULL)
|
|
||||||
xmlFree(prefix);
|
|
||||||
return(cur);
|
|
||||||
}
|
|
||||||
|
|
||||||
static int
|
static int
|
||||||
xmlIsDocNameStartChar(xmlDocPtr doc, int c) {
|
xmlIsDocNameStartChar(xmlDocPtr doc, int c) {
|
||||||
if ((doc == NULL) || (doc->properties & XML_DOC_OLD10) == 0) {
|
if ((doc == NULL) || (doc->properties & XML_DOC_OLD10) == 0) {
|
||||||
@@ -4014,11 +3979,21 @@ xmlValidateAttributeDecl(xmlValidCtxtPtr ctxt, xmlDocPtr doc,
|
|||||||
|
|
||||||
/* One ID per Element Type */
|
/* One ID per Element Type */
|
||||||
if (attr->atype == XML_ATTRIBUTE_ID) {
|
if (attr->atype == XML_ATTRIBUTE_ID) {
|
||||||
|
xmlElementPtr elem = NULL;
|
||||||
|
const xmlChar *elemLocalName;
|
||||||
|
xmlChar *elemPrefix;
|
||||||
int nbId;
|
int nbId;
|
||||||
|
|
||||||
|
elemLocalName = xmlSplitQName4(attr->elem, &elemPrefix);
|
||||||
|
if (elemLocalName == NULL) {
|
||||||
|
xmlVErrMemory(ctxt);
|
||||||
|
return(0);
|
||||||
|
}
|
||||||
|
|
||||||
/* the trick is that we parse DtD as their own internal subset */
|
/* the trick is that we parse DtD as their own internal subset */
|
||||||
xmlElementPtr elem = xmlCtxtGetDtdElementDesc(ctxt, doc->intSubset,
|
if (doc->intSubset != NULL)
|
||||||
attr->elem);
|
elem = xmlHashLookup2(doc->intSubset->elements,
|
||||||
|
elemLocalName, elemPrefix);
|
||||||
if (elem != NULL) {
|
if (elem != NULL) {
|
||||||
nbId = xmlScanIDAttributeDecl(ctxt, elem, 0);
|
nbId = xmlScanIDAttributeDecl(ctxt, elem, 0);
|
||||||
} else {
|
} else {
|
||||||
@@ -4042,7 +4017,8 @@ xmlValidateAttributeDecl(xmlValidCtxtPtr ctxt, xmlDocPtr doc,
|
|||||||
attr->elem, nbId, attr->name);
|
attr->elem, nbId, attr->name);
|
||||||
} else if (doc->extSubset != NULL) {
|
} else if (doc->extSubset != NULL) {
|
||||||
int extId = 0;
|
int extId = 0;
|
||||||
elem = xmlCtxtGetDtdElementDesc(ctxt, doc->extSubset, attr->elem);
|
elem = xmlHashLookup2(doc->extSubset->elements,
|
||||||
|
elemLocalName, elemPrefix);
|
||||||
if (elem != NULL) {
|
if (elem != NULL) {
|
||||||
extId = xmlScanIDAttributeDecl(ctxt, elem, 0);
|
extId = xmlScanIDAttributeDecl(ctxt, elem, 0);
|
||||||
}
|
}
|
||||||
@@ -4056,6 +4032,8 @@ xmlValidateAttributeDecl(xmlValidCtxtPtr ctxt, xmlDocPtr doc,
|
|||||||
attr->elem, attr->name, NULL);
|
attr->elem, attr->name, NULL);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
xmlFree(elemPrefix);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Validity Constraint: Enumeration */
|
/* Validity Constraint: Enumeration */
|
||||||
@@ -4097,6 +4075,8 @@ xmlValidateElementDecl(xmlValidCtxtPtr ctxt, xmlDocPtr doc,
|
|||||||
xmlElementPtr elem) {
|
xmlElementPtr elem) {
|
||||||
int ret = 1;
|
int ret = 1;
|
||||||
xmlElementPtr tst;
|
xmlElementPtr tst;
|
||||||
|
const xmlChar *localName;
|
||||||
|
xmlChar *prefix;
|
||||||
|
|
||||||
CHECK_DTD;
|
CHECK_DTD;
|
||||||
|
|
||||||
@@ -4160,32 +4140,47 @@ xmlValidateElementDecl(xmlValidCtxtPtr ctxt, xmlDocPtr doc,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
localName = xmlSplitQName4(elem->name, &prefix);
|
||||||
|
if (localName == NULL) {
|
||||||
|
xmlVErrMemory(ctxt);
|
||||||
|
return(0);
|
||||||
|
}
|
||||||
|
|
||||||
/* VC: Unique Element Type Declaration */
|
/* VC: Unique Element Type Declaration */
|
||||||
tst = xmlCtxtGetDtdElementDesc(ctxt, doc->intSubset, elem->name);
|
if (doc->intSubset != NULL) {
|
||||||
if ((tst != NULL ) && (tst != elem) &&
|
tst = xmlHashLookup2(doc->intSubset->elements, localName, prefix);
|
||||||
((tst->prefix == elem->prefix) ||
|
|
||||||
(xmlStrEqual(tst->prefix, elem->prefix))) &&
|
if ((tst != NULL ) && (tst != elem) &&
|
||||||
(tst->etype != XML_ELEMENT_TYPE_UNDEFINED)) {
|
((tst->prefix == elem->prefix) ||
|
||||||
xmlErrValidNode(ctxt, (xmlNodePtr) elem, XML_DTD_ELEM_REDEFINED,
|
(xmlStrEqual(tst->prefix, elem->prefix))) &&
|
||||||
"Redefinition of element %s\n",
|
(tst->etype != XML_ELEMENT_TYPE_UNDEFINED)) {
|
||||||
elem->name, NULL, NULL);
|
xmlErrValidNode(ctxt, (xmlNodePtr) elem, XML_DTD_ELEM_REDEFINED,
|
||||||
ret = 0;
|
"Redefinition of element %s\n",
|
||||||
|
elem->name, NULL, NULL);
|
||||||
|
ret = 0;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
tst = xmlCtxtGetDtdElementDesc(ctxt, doc->extSubset, elem->name);
|
if (doc->extSubset != NULL) {
|
||||||
if ((tst != NULL ) && (tst != elem) &&
|
tst = xmlHashLookup2(doc->extSubset->elements, localName, prefix);
|
||||||
((tst->prefix == elem->prefix) ||
|
|
||||||
(xmlStrEqual(tst->prefix, elem->prefix))) &&
|
if ((tst != NULL ) && (tst != elem) &&
|
||||||
(tst->etype != XML_ELEMENT_TYPE_UNDEFINED)) {
|
((tst->prefix == elem->prefix) ||
|
||||||
xmlErrValidNode(ctxt, (xmlNodePtr) elem, XML_DTD_ELEM_REDEFINED,
|
(xmlStrEqual(tst->prefix, elem->prefix))) &&
|
||||||
"Redefinition of element %s\n",
|
(tst->etype != XML_ELEMENT_TYPE_UNDEFINED)) {
|
||||||
elem->name, NULL, NULL);
|
xmlErrValidNode(ctxt, (xmlNodePtr) elem, XML_DTD_ELEM_REDEFINED,
|
||||||
ret = 0;
|
"Redefinition of element %s\n",
|
||||||
|
elem->name, NULL, NULL);
|
||||||
|
ret = 0;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/* One ID per Element Type
|
/* One ID per Element Type
|
||||||
* already done when registering the attribute
|
* already done when registering the attribute
|
||||||
if (xmlScanIDAttributeDecl(ctxt, elem) > 1) {
|
if (xmlScanIDAttributeDecl(ctxt, elem) > 1) {
|
||||||
ret = 0;
|
ret = 0;
|
||||||
} */
|
} */
|
||||||
|
|
||||||
|
xmlFree(prefix);
|
||||||
return(ret);
|
return(ret);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -6525,6 +6520,9 @@ xmlValidateAttributeCallback(void *payload, void *data,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (cur->atype == XML_ATTRIBUTE_NOTATION) {
|
if (cur->atype == XML_ATTRIBUTE_NOTATION) {
|
||||||
|
const xmlChar *elemLocalName;
|
||||||
|
xmlChar *elemPrefix;
|
||||||
|
|
||||||
doc = cur->doc;
|
doc = cur->doc;
|
||||||
if (cur->elem == NULL) {
|
if (cur->elem == NULL) {
|
||||||
xmlErrValid(ctxt, XML_ERR_INTERNAL_ERROR,
|
xmlErrValid(ctxt, XML_ERR_INTERNAL_ERROR,
|
||||||
@@ -6533,14 +6531,25 @@ xmlValidateAttributeCallback(void *payload, void *data,
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (doc != NULL)
|
elemLocalName = xmlSplitQName4(cur->elem, &elemPrefix);
|
||||||
elem = xmlCtxtGetDtdElementDesc(ctxt, doc->intSubset, cur->elem);
|
if (elemLocalName == NULL) {
|
||||||
if ((elem == NULL) && (doc != NULL))
|
xmlVErrMemory(ctxt);
|
||||||
elem = xmlCtxtGetDtdElementDesc(ctxt, doc->extSubset, cur->elem);
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if ((doc != NULL) && (doc->intSubset != NULL))
|
||||||
|
elem = xmlHashLookup2(doc->intSubset->elements,
|
||||||
|
elemLocalName, elemPrefix);
|
||||||
|
if ((elem == NULL) && (doc != NULL) && (doc->extSubset != NULL))
|
||||||
|
elem = xmlHashLookup2(doc->extSubset->elements,
|
||||||
|
elemLocalName, elemPrefix);
|
||||||
if ((elem == NULL) && (cur->parent != NULL) &&
|
if ((elem == NULL) && (cur->parent != NULL) &&
|
||||||
(cur->parent->type == XML_DTD_NODE))
|
(cur->parent->type == XML_DTD_NODE))
|
||||||
elem = xmlCtxtGetDtdElementDesc(ctxt, (xmlDtdPtr) cur->parent,
|
elem = xmlHashLookup2(((xmlDtdPtr) cur->parent)->elements,
|
||||||
cur->elem);
|
elemLocalName, elemPrefix);
|
||||||
|
|
||||||
|
xmlFree(elemPrefix);
|
||||||
|
|
||||||
if (elem == NULL) {
|
if (elem == NULL) {
|
||||||
xmlErrValidNode(ctxt, NULL, XML_DTD_UNKNOWN_ELEM,
|
xmlErrValidNode(ctxt, NULL, XML_DTD_UNKNOWN_ELEM,
|
||||||
"attribute %s: could not find decl for element %s\n",
|
"attribute %s: could not find decl for element %s\n",
|
||||||
|
|||||||
Reference in New Issue
Block a user