153aa9179Sopenharmony_ciFrom 691f7eb44dd82a3de79e492bbe6c5426c96cbdde Mon Sep 17 00:00:00 2001
253aa9179Sopenharmony_ciFrom: Nick Wellnhofer <wellnhofer@aevum.de>
353aa9179Sopenharmony_ciDate: Wed, 15 Feb 2023 14:05:13 +0100
453aa9179Sopenharmony_ciSubject: [PATCH] malloc-fail: Fix memory leak in xmlXPathCompareValues
553aa9179Sopenharmony_ci
653aa9179Sopenharmony_ciFound with libFuzzer, see #344.
753aa9179Sopenharmony_ci
853aa9179Sopenharmony_ciReference:https://github.com/GNOME/libxml2/commit/691f7eb44dd82a3de79e492bbe6c5426c96cbdde
953aa9179Sopenharmony_ciConflict:NA
1053aa9179Sopenharmony_ci---
1153aa9179Sopenharmony_ci xpath.c | 5 +++--
1253aa9179Sopenharmony_ci 1 file changed, 3 insertions(+), 2 deletions(-)
1353aa9179Sopenharmony_ci
1453aa9179Sopenharmony_cidiff --git a/xpath.c b/xpath.c
1553aa9179Sopenharmony_ciindex 212a4e0..c1d119b 100644
1653aa9179Sopenharmony_ci--- a/xpath.c
1753aa9179Sopenharmony_ci+++ b/xpath.c
1853aa9179Sopenharmony_ci@@ -7375,14 +7375,14 @@ xmlXPathCompareValues(xmlXPathParserContextPtr ctxt, int inf, int strict) {
1953aa9179Sopenharmony_ci 	valuePush(ctxt, arg1);
2053aa9179Sopenharmony_ci 	xmlXPathNumberFunction(ctxt, 1);
2153aa9179Sopenharmony_ci 	arg1 = valuePop(ctxt);
2253aa9179Sopenharmony_ci-        CHECK_ERROR0;
2353aa9179Sopenharmony_ci     }
2453aa9179Sopenharmony_ci     if (arg2->type != XPATH_NUMBER) {
2553aa9179Sopenharmony_ci 	valuePush(ctxt, arg2);
2653aa9179Sopenharmony_ci 	xmlXPathNumberFunction(ctxt, 1);
2753aa9179Sopenharmony_ci 	arg2 = valuePop(ctxt);
2853aa9179Sopenharmony_ci-        CHECK_ERROR0;
2953aa9179Sopenharmony_ci     }
3053aa9179Sopenharmony_ci+    if (ctxt->error)
3153aa9179Sopenharmony_ci+        goto error;
3253aa9179Sopenharmony_ci     /*
3353aa9179Sopenharmony_ci      * Add tests for infinity and nan
3453aa9179Sopenharmony_ci      * => feedback on 3.4 for Inf and NaN
3553aa9179Sopenharmony_ci@@ -7432,6 +7432,7 @@ xmlXPathCompareValues(xmlXPathParserContextPtr ctxt, int inf, int strict) {
3653aa9179Sopenharmony_ci 	    }
3753aa9179Sopenharmony_ci 	}
3853aa9179Sopenharmony_ci     }
3953aa9179Sopenharmony_ci+error:
4053aa9179Sopenharmony_ci     xmlXPathReleaseObject(ctxt->context, arg1);
4153aa9179Sopenharmony_ci     xmlXPathReleaseObject(ctxt->context, arg2);
4253aa9179Sopenharmony_ci     return(ret);
4353aa9179Sopenharmony_ci-- 
4453aa9179Sopenharmony_ci2.27.0
4553aa9179Sopenharmony_ci
46