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 634005 - xmlSAX2StartElementNS creates malformed tree (with patch)
xmlSAX2StartElementNS creates malformed tree (with patch)
Status: RESOLVED OBSOLETE
Product: libxml2
Classification: Platform
Component: general
2.7.6
Other Linux
: Normal normal
: ---
Assigned To: Daniel Veillard
libxml QA maintainers
Depends on:
Blocks:
 
 
Reported: 2010-11-04 16:49 UTC by Mike Dalessio
Modified: 2021-07-05 13:20 UTC
See Also:
GNOME target: ---
GNOME version: ---



Description Mike Dalessio 2010-11-04 16:49:19 UTC
Under the right circumstances, xmlSAX2StartElementNS will construct a malformed tree, in that the child of a parent will have parent == NULL.

Example code and a patch to SAX2.c (v 2.7.7) are posted at:

  https://gist.github.com/662758

Summary:

  printf("doc2 %p, doc2->children %p, doc2->children->parent %p\n",
         doc2, doc2->children, doc2->children ? doc2->children->parent : NULL);

will output

  doc2 0x164b390, doc2->children 0x164cd40, doc2->children->parent (nil)

This malformed document can easily be made to segfault during xmlFreeDoc (as the gisted example code demonstrates).

This simple patch fixes the bug:


diff --git a/SAX2.c b/SAX2.c
index 84c1f00..fac870d 100644
--- a/SAX2.c
+++ b/SAX2.c
@@ -2264,6 +2264,7 @@ xmlSAX2StartElementNs(void *ctx,
      * Link the child element
      */
     if (parent != NULL) {
+        xmlUnlinkNode(ret);
         if (parent->type == XML_ELEMENT_NODE) {
 	    xmlAddChild(parent, ret);
 	} else {


It appears that xmlSAX2StartElement may have the same issue, though I have not written demonstration code for that function.

This issue was originally discovered via https://github.com/tenderlove/nokogiri/issues/issue/362

Thanks for your time.
Comment 1 GNOME Infrastructure Team 2021-07-05 13:20:51 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.