Skip to content

Commit 40da71e

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. On failure, release whichever of href/prefix did allocate, free the xmlNs, and return without linking it. Matches the existing xmlMalloc(ns) early-return convention above.
1 parent 171b722 commit 40da71e

1 file changed

Lines changed: 12 additions & 0 deletions

File tree

ext/xsl/xsltprocessor.c

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,18 @@ 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+
if (ns->href) {
146+
xmlFree(ns->href);
147+
}
148+
if (ns->prefix) {
149+
xmlFree(ns->prefix);
150+
}
151+
xmlFree(ns);
152+
return;
153+
}
154+
143155
ns->next = node->nsDef;
144156
node->nsDef = ns;
145157
}

0 commit comments

Comments
 (0)