Skip to content

Commit c39ec30

Browse files
stevecheckowayflavorjones
authored andcommitted
fix memsize_node when called on xmlAttrs
The `properties` field of an `xmlNode` element points to an `xmlAttr`. The first few fields of `xmlAttr` are in common with `xmlNode`, but not the `properties` field which doesn't exist in an `xmlAttr`. The `memsize_node` function was passing an `xmlAttr` to a recursive call and then trying to do the same with the properties of that. This led to type confusion and subsequent crashes. Fixes: #2923 (cherry picked from commit 81762fa)
1 parent 1617d54 commit c39ec30

File tree

1 file changed

+5
-2
lines changed

1 file changed

+5
-2
lines changed

ext/nokogiri/xml_document.c

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -103,8 +103,11 @@ memsize_node(const xmlNodePtr node)
103103
size_t memsize = 0;
104104

105105
memsize += xmlStrlen(node->name);
106-
for (child = (xmlNodePtr)node->properties; child; child = child->next) {
107-
memsize += sizeof(xmlAttr) + memsize_node(child);
106+
107+
if (node->type == XML_ELEMENT_NODE) {
108+
for (child = (xmlNodePtr)node->properties; child; child = child->next) {
109+
memsize += sizeof(xmlAttr) + memsize_node(child);
110+
}
108111
}
109112
if (node->type == XML_TEXT_NODE) {
110113
memsize += xmlStrlen(node->content);

0 commit comments

Comments
 (0)