summaryrefslogtreecommitdiff
path: root/xpath.c
diff options
context:
space:
mode:
authorNick Wellnhofer <wellnhofer@aevum.de>2023-02-26 18:00:30 +0100
committerNick Wellnhofer <wellnhofer@aevum.de>2023-02-27 17:18:08 +0100
commitbc9f372c1001ff64353400edf489fb0ce4ab17fc (patch)
tree384ca167f5ab315478741b281de8c79f1d994c08 /xpath.c
parent6f9604f0e3e52e96881ab3b662f35fbe04cd49ac (diff)
downloadlibxml2-bc9f372c1001ff64353400edf489fb0ce4ab17fc.tar.gz
malloc-fail: Fix memory leak in xmlXPathDistinctSorted
Found with libFuzzer, see #344.
Diffstat (limited to 'xpath.c')
-rw-r--r--xpath.c13
1 files changed, 10 insertions, 3 deletions
diff --git a/xpath.c b/xpath.c
index b358cc06..d3828335 100644
--- a/xpath.c
+++ b/xpath.c
@@ -4560,16 +4560,23 @@ xmlXPathDistinctSorted (xmlNodeSetPtr nodes) {
cur = xmlXPathNodeSetItem(nodes, i);
strval = xmlXPathCastNodeToString(cur);
if (xmlHashLookup(hash, strval) == NULL) {
- xmlHashAddEntry(hash, strval, strval);
- /* TODO: Propagate memory error. */
+ if (xmlHashAddEntry(hash, strval, strval) < 0) {
+ xmlFree(strval);
+ goto error;
+ }
if (xmlXPathNodeSetAddUnique(ret, cur) < 0)
- break;
+ goto error;
} else {
xmlFree(strval);
}
}
xmlHashFree(hash, xmlHashDefaultDeallocator);
return(ret);
+
+error:
+ xmlHashFree(hash, xmlHashDefaultDeallocator);
+ xmlXPathFreeNodeSet(ret);
+ return(NULL);
}
/**