After an evaluation, GNOME has moved from Bugzilla to GitLab. Learn more about GitLab.
No new issues can be reported in GNOME Bugzilla anymore.
To report an issue in a GNOME project, go to GNOME GitLab.
Do not go to GNOME Gitlab for: Bluefish, Doxygen, GnuCash, GStreamer, java-gnome, LDTP, NetworkManager, Tomboy.
Bug 691742 - xmlNewProp on existing attribute ignores NULL return from xmlAddID
xmlNewProp on existing attribute ignores NULL return from xmlAddID
Status: RESOLVED OBSOLETE
Product: libxml2
Classification: Platform
Component: general
git master
Other All
: Normal normal
: ---
Assigned To: Daniel Veillard
libxml QA maintainers
Depends on:
Blocks:
 
 
Reported: 2013-01-14 21:13 UTC by Michael Pelletier
Modified: 2021-07-05 13:21 UTC
See Also:
GNOME target: ---
GNOME version: ---



Description Michael Pelletier 2013-01-14 21:13:12 UTC
When xmlNewPropInternal() operates on an attribute which already exists, an error return from xmlAddID is ignored, and the value supplied to xmlNewProp() won't match the attribute value unless it already did.

In the valid.c file looking at xmlAddID, you wind up in this section if the attribute you're attempting to add is already present - and NULL is returned:

-----
    if (xmlHashAddEntry(table, value, ret) < 0) {
#ifdef LIBXML_VALID_ENABLED
    /*
     * The id is already defined in this DTD.
     */
    if ((ctxt != NULL) && (ctxt->error != NULL)) {
        xmlErrValidNode(ctxt, attr->parent, XML_DTD_ID_REDEFINED,
                        "ID %s already defined\n",
                value, NULL, NULL);
    }
#endif /* LIBXML_VALID_ENABLED */
    xmlFreeID(ret);
    return(NULL);
    }
-----

But in xmlNewPropInternal() in tree.c, the return value is disregarded:

-----
    if ((value != NULL) && (node != NULL) &&
        (xmlIsID(node->doc, node, cur) == 1))
        xmlAddID(NULL, node->doc, value, cur);

    if ((__xmlRegisterCallbacks) && (xmlRegisterNodeDefaultValue))
        xmlRegisterNodeDefaultValue((xmlNodePtr) cur);
    return (cur);
}
-----

So the attribute may not match what was given to xmlNewProp(), but xmlNewProp() never finds out about it. While it's true that one should use "SetProp" to change existing attributes, it seems like a NewProp call that does not result in the attribute value being set to what was supplied should be flagged in some way.

Or at least we should clarify the xmlNewProp documentation a bit to make it clear that in order to "create-or-update" an attribute, you have to NewProp, then check the value, then SetProp if it doesn't match - or some variant of that.
Comment 1 GNOME Infrastructure Team 2021-07-05 13:21:23 UTC
GNOME is going to shut down bugzilla.gnome.org in favor of gitlab.gnome.org.
As part of that, we are mass-closing older open tickets in bugzilla.gnome.org
which have not seen updates for a longer time (resources are unfortunately
quite limited so not every ticket can get handled).

If you can still reproduce the situation described in this ticket in a recent
and supported software version, then please follow
  https://wiki.gnome.org/GettingInTouch/BugReportingGuidelines
and create a new ticket at
  https://gitlab.gnome.org/GNOME/libxml2/-/issues/

Thank you for your understanding and your help.