Commit 9b02e295 authored by Kasimier T. Buchcik's avatar Kasimier T. Buchcik
Browse files

Fixed bug #341337, reported by David Grohmann. The code expected a node

* xmlschemas.c: Fixed bug #341337, reported by David Grohmann.
  The code expected a node (xmlNodePtr) on the info for a
  non-existent default attribute, which clearly cannot be
  expected, since the attribute does not exist. I can only
  guess that this sneaked trying to eliminate the query
  for the owner-element, which is unavoidable actually.
  Note that creation of default attributes won't have an
  effect if validating via SAX/XMLReader; i.e., the processor
  won't fire additional start-attribute events (I'm not even
  sure if Libxml2 has such a SAX-event; I think it hands them
  all over in the start-element event).
parent 7c7c0590
Thu May 11 18:03:49 CEST 2006 Kasimier Buchcik <libxml2-cvs@cazic.net>
* xmlschemas.c: Fixed bug #341337, reported by David Grohmann.
The code expected a node (xmlNodePtr) on the info for a
non-existent default attribute, which clearly cannot be
expected, since the attribute does not exist. I can only
guess that this sneaked trying to eliminate the query
for the owner-element, which is unavoidable actually.
Note that creation of default attributes won't have an
effect if validating via SAX/XMLReader; i.e., the processor
won't fire additional start-attribute events (I'm not even
sure if Libxml2 has such a SAX-event; I think it hands them
all over in the start-element event).
Tue May 9 21:47:58 CEST 2006 Kasimier Buchcik <libxml2-cvs@cazic.net> Tue May 9 21:47:58 CEST 2006 Kasimier Buchcik <libxml2-cvs@cazic.net>
* xmlschemas.c: Fixed bug #341150, reported by Michael Romer. * xmlschemas.c: Fixed bug #341150, reported by Michael Romer.
...@@ -11,7 +25,6 @@ Tue May 9 21:47:58 CEST 2006 Kasimier Buchcik <libxml2-cvs@cazic.net> ...@@ -11,7 +25,6 @@ Tue May 9 21:47:58 CEST 2006 Kasimier Buchcik <libxml2-cvs@cazic.net>
result/schemas/subst-group-1_0_1.err: Added regression test result/schemas/subst-group-1_0_1.err: Added regression test
supplied by Michael Romer for bug #341150. supplied by Michael Romer for bug #341150.
Sat May 6 11:05:24 HKT 2006 William M. Brack <wbrack@mmm.com.hk> Sat May 6 11:05:24 HKT 2006 William M. Brack <wbrack@mmm.com.hk>
* relaxng.c: Fixed compilation error with patch supplied by * relaxng.c: Fixed compilation error with patch supplied by
......
...@@ -24823,9 +24823,10 @@ xmlSchemaVAttributesComplex(xmlSchemaValidCtxtPtr vctxt) ...@@ -24823,9 +24823,10 @@ xmlSchemaVAttributesComplex(xmlSchemaValidCtxtPtr vctxt)
xmlSchemaItemListPtr attrUseList; xmlSchemaItemListPtr attrUseList;
xmlSchemaAttributeUsePtr attrUse = NULL; xmlSchemaAttributeUsePtr attrUse = NULL;
xmlSchemaAttributePtr attrDecl = NULL; xmlSchemaAttributePtr attrDecl = NULL;
xmlSchemaAttrInfoPtr iattr, tmpiattr; xmlSchemaAttrInfoPtr iattr, tmpiattr;
int i, j, found, nbAttrs, nbUses; int i, j, found, nbAttrs, nbUses;
int xpathRes = 0, res, wildIDs = 0, fixed; int xpathRes = 0, res, wildIDs = 0, fixed;
xmlNodePtr defAttrOwnerElem = NULL;
/* /*
* SPEC (cvc-attribute) * SPEC (cvc-attribute)
...@@ -25067,6 +25068,15 @@ xmlSchemaVAttributesComplex(xmlSchemaValidCtxtPtr vctxt) ...@@ -25067,6 +25068,15 @@ xmlSchemaVAttributesComplex(xmlSchemaValidCtxtPtr vctxt)
if (vctxt->nbAttrInfos == 0) if (vctxt->nbAttrInfos == 0)
return (0); return (0);
/*
* Get the owner element; needed for creation of default attributes.
* This fixes bug #341337, reported by David Grohmann.
*/
if (vctxt->options & XML_SCHEMA_VAL_VC_I_CREATE) {
xmlSchemaNodeInfoPtr ielem = vctxt->elemInfos[vctxt->depth];
if (ielem && ielem->node && ielem->node->doc)
defAttrOwnerElem = ielem->node;
}
/* /*
* Validate values, create default attributes, evaluate IDCs. * Validate values, create default attributes, evaluate IDCs.
*/ */
...@@ -25108,8 +25118,10 @@ xmlSchemaVAttributesComplex(xmlSchemaValidCtxtPtr vctxt) ...@@ -25108,8 +25118,10 @@ xmlSchemaVAttributesComplex(xmlSchemaValidCtxtPtr vctxt)
if (iattr->state == XML_SCHEMAS_ATTR_DEFAULT) { if (iattr->state == XML_SCHEMAS_ATTR_DEFAULT) {
/* /*
* Default/fixed attributes. * Default/fixed attributes.
* We need the value only if we need to resolve IDCs or
* will create default attributes.
*/ */
if (xpathRes) { if ((xpathRes) || (defAttrOwnerElem)) {
if (iattr->use->defValue != NULL) { if (iattr->use->defValue != NULL) {
iattr->value = (xmlChar *) iattr->use->defValue; iattr->value = (xmlChar *) iattr->use->defValue;
iattr->val = iattr->use->defVal; iattr->val = iattr->use->defVal;
...@@ -25139,8 +25151,8 @@ xmlSchemaVAttributesComplex(xmlSchemaValidCtxtPtr vctxt) ...@@ -25139,8 +25151,8 @@ xmlSchemaVAttributesComplex(xmlSchemaValidCtxtPtr vctxt)
* VAL TODO: Should we use the *normalized* value? This currently * VAL TODO: Should we use the *normalized* value? This currently
* uses the *initial* value. * uses the *initial* value.
*/ */
if ((vctxt->options & XML_SCHEMA_VAL_VC_I_CREATE) &&
(iattr->node != NULL) && (iattr->node->doc != NULL)) { if (defAttrOwnerElem) {
xmlChar *normValue; xmlChar *normValue;
const xmlChar *value; const xmlChar *value;
...@@ -25154,7 +25166,7 @@ xmlSchemaVAttributesComplex(xmlSchemaValidCtxtPtr vctxt) ...@@ -25154,7 +25166,7 @@ xmlSchemaVAttributesComplex(xmlSchemaValidCtxtPtr vctxt)
value = BAD_CAST normValue; value = BAD_CAST normValue;
if (iattr->nsName == NULL) { if (iattr->nsName == NULL) {
if (xmlNewProp(iattr->node->parent, if (xmlNewProp(defAttrOwnerElem,
iattr->localName, value) == NULL) { iattr->localName, value) == NULL) {
VERROR_INT("xmlSchemaVAttributesComplex", VERROR_INT("xmlSchemaVAttributesComplex",
"callling xmlNewProp()"); "callling xmlNewProp()");
...@@ -25165,8 +25177,8 @@ xmlSchemaVAttributesComplex(xmlSchemaValidCtxtPtr vctxt) ...@@ -25165,8 +25177,8 @@ xmlSchemaVAttributesComplex(xmlSchemaValidCtxtPtr vctxt)
} else { } else {
xmlNsPtr ns; xmlNsPtr ns;
ns = xmlSearchNsByHref(iattr->node->doc, ns = xmlSearchNsByHref(defAttrOwnerElem->doc,
iattr->node->parent, iattr->nsName); defAttrOwnerElem, iattr->nsName);
if (ns == NULL) { if (ns == NULL) {
xmlChar prefix[12]; xmlChar prefix[12];
int counter = 0; int counter = 0;
...@@ -25177,8 +25189,8 @@ xmlSchemaVAttributesComplex(xmlSchemaValidCtxtPtr vctxt) ...@@ -25177,8 +25189,8 @@ xmlSchemaVAttributesComplex(xmlSchemaValidCtxtPtr vctxt)
*/ */
do { do {
snprintf((char *) prefix, 12, "p%d", counter++); snprintf((char *) prefix, 12, "p%d", counter++);
ns = xmlSearchNs(iattr->node->doc, ns = xmlSearchNs(defAttrOwnerElem->doc,
iattr->node->parent, BAD_CAST prefix); defAttrOwnerElem, BAD_CAST prefix);
if (counter > 1000) { if (counter > 1000) {
VERROR_INT( VERROR_INT(
"xmlSchemaVAttributesComplex", "xmlSchemaVAttributesComplex",
...@@ -25198,8 +25210,7 @@ xmlSchemaVAttributesComplex(xmlSchemaValidCtxtPtr vctxt) ...@@ -25198,8 +25210,7 @@ xmlSchemaVAttributesComplex(xmlSchemaValidCtxtPtr vctxt)
* If we have QNames: do we need to ensure there's a * If we have QNames: do we need to ensure there's a
* prefix defined for the QName? * prefix defined for the QName?
*/ */
xmlNewNsProp(iattr->node->parent, ns, xmlNewNsProp(defAttrOwnerElem, ns, iattr->localName, value);
iattr->localName, value);
} }
if (normValue != NULL) if (normValue != NULL)
xmlFree(normValue); xmlFree(normValue);
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment