Skip to content

Commit 0a1271e

Browse files
committed
ext/xsl: discard partially-constructed ns on xmlStrdup failure
If xmlStrdup fails for either href or prefix in xsl_add_ns_def, the malformed xmlNs (NULL href, or NULL prefix when one was expected) was linked into node->nsDef. Subsequent libxml2 traversal of the namespace chain dereferenced those NULLs. Free the xmlNs via xmlFreeNs and return without linking it.
1 parent 171b722 commit 0a1271e

1 file changed

Lines changed: 6 additions & 0 deletions

File tree

ext/xsl/xsltprocessor.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,12 @@ static void xsl_add_ns_def(xmlNodePtr node)
140140
ns->type = XML_LOCAL_NAMESPACE;
141141
ns->href = should_free ? attr_value : xmlStrdup(attr_value);
142142
ns->prefix = attr->ns->prefix ? xmlStrdup(attr->name) : NULL;
143+
144+
if (UNEXPECTED(ns->href == NULL || (attr->ns->prefix != NULL && ns->prefix == NULL))) {
145+
xmlFreeNs(ns);
146+
return;
147+
}
148+
143149
ns->next = node->nsDef;
144150
node->nsDef = ns;
145151
}

0 commit comments

Comments
 (0)