GNOME Bugzilla – Bug 766828
xmlParseStartTag2() contains typo when checking for default definitions for an attribute in a namespace
Last modified: 2021-07-05 13:23:29 UTC
While reviewing the undefined behavior issues reported in Bug 752902, I tried changing the declaration of struct _xmlDefAttrs from this: typedef struct _xmlDefAttrs xmlDefAttrs; typedef xmlDefAttrs *xmlDefAttrsPtr; struct _xmlDefAttrs { int nbAttrs; /* number of defaulted attributes on that element */ int maxAttrs; /* the size of the array */ const xmlChar *values[5]; /* array of localname/prefix/values/external */ }; to this: typedef struct _xmlDefAttrs xmlDefAttrs; typedef xmlDefAttrs *xmlDefAttrsPtr; struct _xmlDefAttrs { int nbAttrs; /* number of defaulted attributes on that element */ int maxAttrs; /* the size of the array */ const xmlChar *values[][5]; /* array of localname/prefix/values/external */ }; Then fixed the resulting compiler errors. The resulted in finding the following bug in xmlParseStartTag2(): nsname = xmlGetNamespace(ctxt, attname); if (nsname != defaults->values[2]) { // Bad offset! if (nsPush(ctxt, attname, defaults->values[5 * i + 2]) > 0) nbNs++; } With the structure change, that should be: nsname = xmlGetNamespace(ctxt, attname); if (nsname != defaults->values[i][2]) { // Fixed! if (nsPush(ctxt, attname, defaults->values[i][2]) > 0) nbNs++; } If we don't make the structure change, it should be: nsname = xmlGetNamespace(ctxt, attname); if (nsname != defaults->values[5 * i + 2]) { // Fixed! if (nsPush(ctxt, attname, defaults->values[5 * i + 2]) > 0) nbNs++; }
Note that this regression occurred back in September 2003 with commit e57ec790de9de71a3b646a853447a842f4fc3c9b: <https://git.gnome.org/browse/libxml2/commit/?id=e57ec790de9de71a3b646a853447a842f4fc3c9b>
Nick fixed Undefined Behavior Sanitizer (UBSan) warnings in this code here: https://git.gnome.org/browse/libxml2/commit/?id=474967241cdcce6d3a2fd356079571eee794ec12 However, the bug described here still exists.
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.