File libxml2-CVE-2025-9714-1.patch of Package libxml2.41582
From 5153c7baceca65f575efdcbb0244860d97031f96 Mon Sep 17 00:00:00 2001
From: Nick Wellnhofer <wellnhofer@aevum.de>
Date: Mon, 18 Mar 2019 11:18:31 +0100
Subject: [PATCH] Use break statements in xmlXPathCompOpEval
This prepares for the next commit.
---
xpath.c | 133 ++++++++++++++++++++++++++++++--------------------------
1 file changed, 72 insertions(+), 61 deletions(-)
Index: libxml2-2.9.7/xpath.c
===================================================================
--- libxml2-2.9.7.orig/xpath.c
+++ libxml2-2.9.7/xpath.c
@@ -12809,7 +12809,7 @@ xmlXPathCompOpEvalFirst(xmlXPathParserCo
comp = ctxt->comp;
switch (op->op) {
case XPATH_OP_END:
- return (0);
+ break;
case XPATH_OP_UNION:
total =
xmlXPathCompOpEvalFirst(ctxt, &comp->steps[op->ch1],
@@ -12855,7 +12855,7 @@ xmlXPathCompOpEvalFirst(xmlXPathParserCo
arg2->nodesetval->nodeNr) < 0)))) {
xmlXPathReleaseObject(ctxt->context, arg1);
xmlXPathReleaseObject(ctxt->context, arg2);
- return(0);
+ break;
}
arg1->nodesetval = xmlXPathNodeSetMerge(arg1->nodesetval,
@@ -12865,10 +12865,11 @@ xmlXPathCompOpEvalFirst(xmlXPathParserCo
/* optimizer */
if (total > cur)
xmlXPathCompSwap(op);
- return (total + cur);
+ total += cur;
+ break;
case XPATH_OP_ROOT:
xmlXPathRoot(ctxt);
- return (0);
+ break;
case XPATH_OP_NODE:
if (op->ch1 != -1)
total += xmlXPathCompOpEval(ctxt, &comp->steps[op->ch1]);
@@ -12878,7 +12879,7 @@ xmlXPathCompOpEvalFirst(xmlXPathParserCo
CHECK_ERROR0;
valuePush(ctxt, xmlXPathCacheNewNodeSet(ctxt->context,
ctxt->context->node));
- return (total);
+ break;
case XPATH_OP_RESET:
if (op->ch1 != -1)
total += xmlXPathCompOpEval(ctxt, &comp->steps[op->ch1]);
@@ -12887,22 +12888,22 @@ xmlXPathCompOpEvalFirst(xmlXPathParserCo
total += xmlXPathCompOpEval(ctxt, &comp->steps[op->ch2]);
CHECK_ERROR0;
ctxt->context->node = NULL;
- return (total);
+ break;
case XPATH_OP_COLLECT:{
if (op->ch1 == -1)
- return (total);
+ break;
total = xmlXPathCompOpEval(ctxt, &comp->steps[op->ch1]);
CHECK_ERROR0;
total += xmlXPathNodeCollectAndTest(ctxt, op, first, NULL, 0);
- return (total);
+ break;
}
case XPATH_OP_VALUE:
valuePush(ctxt,
xmlXPathCacheObjectCopy(ctxt->context,
(xmlXPathObjectPtr) op->value4));
- return (0);
+ break;
case XPATH_OP_SORT:
if (op->ch1 != -1)
total +=
@@ -12914,15 +12915,18 @@ xmlXPathCompOpEvalFirst(xmlXPathParserCo
&& (ctxt->value->nodesetval != NULL)
&& (ctxt->value->nodesetval->nodeNr > 1))
xmlXPathNodeSetSort(ctxt->value->nodesetval);
- return (total);
+ break;
#ifdef XP_OPTIMIZED_FILTER_FIRST
case XPATH_OP_FILTER:
total += xmlXPathCompOpEvalFilterFirst(ctxt, op, first);
- return (total);
+ break;
#endif
default:
- return (xmlXPathCompOpEval(ctxt, op));
+ total += xmlXPathCompOpEval(ctxt, op);
+ break;
}
+
+ return(total);
}
/**
@@ -12954,7 +12958,7 @@ xmlXPathCompOpEvalLast(xmlXPathParserCon
comp = ctxt->comp;
switch (op->op) {
case XPATH_OP_END:
- return (0);
+ break;
case XPATH_OP_UNION:
bakd = ctxt->context->doc;
bak = ctxt->context->node;
@@ -13007,7 +13011,7 @@ xmlXPathCompOpEvalLast(xmlXPathParserCon
arg2->nodesetval->nodeNr) < 0)))) {
xmlXPathReleaseObject(ctxt->context, arg1);
xmlXPathReleaseObject(ctxt->context, arg2);
- return(0);
+ break;
}
arg1->nodesetval = xmlXPathNodeSetMerge(arg1->nodesetval,
@@ -13017,10 +13021,11 @@ xmlXPathCompOpEvalLast(xmlXPathParserCon
/* optimizer */
if (total > cur)
xmlXPathCompSwap(op);
- return (total + cur);
+ total += cur;
+ break;
case XPATH_OP_ROOT:
xmlXPathRoot(ctxt);
- return (0);
+ break;
case XPATH_OP_NODE:
if (op->ch1 != -1)
total += xmlXPathCompOpEval(ctxt, &comp->steps[op->ch1]);
@@ -13030,7 +13035,7 @@ xmlXPathCompOpEvalLast(xmlXPathParserCon
CHECK_ERROR0;
valuePush(ctxt, xmlXPathCacheNewNodeSet(ctxt->context,
ctxt->context->node));
- return (total);
+ break;
case XPATH_OP_RESET:
if (op->ch1 != -1)
total += xmlXPathCompOpEval(ctxt, &comp->steps[op->ch1]);
@@ -13039,22 +13044,22 @@ xmlXPathCompOpEvalLast(xmlXPathParserCon
total += xmlXPathCompOpEval(ctxt, &comp->steps[op->ch2]);
CHECK_ERROR0;
ctxt->context->node = NULL;
- return (total);
+ break;
case XPATH_OP_COLLECT:{
if (op->ch1 == -1)
- return (0);
+ break;
total += xmlXPathCompOpEval(ctxt, &comp->steps[op->ch1]);
CHECK_ERROR0;
total += xmlXPathNodeCollectAndTest(ctxt, op, NULL, last, 0);
- return (total);
+ break;
}
case XPATH_OP_VALUE:
valuePush(ctxt,
xmlXPathCacheObjectCopy(ctxt->context,
(xmlXPathObjectPtr) op->value4));
- return (0);
+ break;
case XPATH_OP_SORT:
if (op->ch1 != -1)
total +=
@@ -13066,10 +13071,13 @@ xmlXPathCompOpEvalLast(xmlXPathParserCon
&& (ctxt->value->nodesetval != NULL)
&& (ctxt->value->nodesetval->nodeNr > 1))
xmlXPathNodeSetSort(ctxt->value->nodesetval);
- return (total);
+ break;
default:
- return (xmlXPathCompOpEval(ctxt, op));
+ total += xmlXPathCompOpEval(ctxt, op);
+ break;
}
+
+ return (total);
}
#ifdef XP_OPTIMIZED_FILTER_FIRST
@@ -13391,7 +13399,7 @@ xmlXPathCompOpEval(xmlXPathParserContext
comp = ctxt->comp;
switch (op->op) {
case XPATH_OP_END:
- return (0);
+ break;
case XPATH_OP_AND:
bakd = ctxt->context->doc;
bak = ctxt->context->node;
@@ -13401,7 +13409,7 @@ xmlXPathCompOpEval(xmlXPathParserContext
CHECK_ERROR0;
xmlXPathBooleanFunction(ctxt, 1);
if ((ctxt->value == NULL) || (ctxt->value->boolval == 0))
- return (total);
+ break;
arg2 = valuePop(ctxt);
ctxt->context->doc = bakd;
ctxt->context->node = bak;
@@ -13410,13 +13418,13 @@ xmlXPathCompOpEval(xmlXPathParserContext
total += xmlXPathCompOpEval(ctxt, &comp->steps[op->ch2]);
if (ctxt->error) {
xmlXPathFreeObject(arg2);
- return(0);
+ break;
}
xmlXPathBooleanFunction(ctxt, 1);
if (ctxt->value != NULL)
ctxt->value->boolval &= arg2->boolval;
xmlXPathReleaseObject(ctxt->context, arg2);
- return (total);
+ break;
case XPATH_OP_OR:
bakd = ctxt->context->doc;
bak = ctxt->context->node;
@@ -13426,7 +13434,7 @@ xmlXPathCompOpEval(xmlXPathParserContext
CHECK_ERROR0;
xmlXPathBooleanFunction(ctxt, 1);
if ((ctxt->value == NULL) || (ctxt->value->boolval == 1))
- return (total);
+ break;
arg2 = valuePop(ctxt);
ctxt->context->doc = bakd;
ctxt->context->node = bak;
@@ -13435,13 +13443,13 @@ xmlXPathCompOpEval(xmlXPathParserContext
total += xmlXPathCompOpEval(ctxt, &comp->steps[op->ch2]);
if (ctxt->error) {
xmlXPathFreeObject(arg2);
- return(0);
+ break;
}
xmlXPathBooleanFunction(ctxt, 1);
if (ctxt->value != NULL)
ctxt->value->boolval |= arg2->boolval;
xmlXPathReleaseObject(ctxt->context, arg2);
- return (total);
+ break;
case XPATH_OP_EQUAL:
bakd = ctxt->context->doc;
bak = ctxt->context->node;
@@ -13460,7 +13468,7 @@ xmlXPathCompOpEval(xmlXPathParserContext
else
equal = xmlXPathNotEqualValues(ctxt);
valuePush(ctxt, xmlXPathCacheNewBoolean(ctxt->context, equal));
- return (total);
+ break;
case XPATH_OP_CMP:
bakd = ctxt->context->doc;
bak = ctxt->context->node;
@@ -13476,7 +13484,7 @@ xmlXPathCompOpEval(xmlXPathParserContext
CHECK_ERROR0;
ret = xmlXPathCompareValues(ctxt, op->value, op->value2);
valuePush(ctxt, xmlXPathCacheNewBoolean(ctxt->context, ret));
- return (total);
+ break;
case XPATH_OP_PLUS:
bakd = ctxt->context->doc;
bak = ctxt->context->node;
@@ -13502,7 +13510,7 @@ xmlXPathCompOpEval(xmlXPathParserContext
CAST_TO_NUMBER;
CHECK_TYPE0(XPATH_NUMBER);
}
- return (total);
+ break;
case XPATH_OP_MULT:
bakd = ctxt->context->doc;
bak = ctxt->context->node;
@@ -13522,7 +13530,7 @@ xmlXPathCompOpEval(xmlXPathParserContext
xmlXPathDivValues(ctxt);
else if (op->value == 2)
xmlXPathModValues(ctxt);
- return (total);
+ break;
case XPATH_OP_UNION:
bakd = ctxt->context->doc;
bak = ctxt->context->node;
@@ -13554,7 +13562,7 @@ xmlXPathCompOpEval(xmlXPathParserContext
arg2->nodesetval->nodeNr) < 0)))) {
xmlXPathReleaseObject(ctxt->context, arg1);
xmlXPathReleaseObject(ctxt->context, arg2);
- return(0);
+ break;
}
if ((arg1->nodesetval == NULL) ||
@@ -13567,10 +13575,10 @@ xmlXPathCompOpEval(xmlXPathParserContext
valuePush(ctxt, arg1);
xmlXPathReleaseObject(ctxt->context, arg2);
- return (total);
+ break;
case XPATH_OP_ROOT:
xmlXPathRoot(ctxt);
- return (total);
+ break;
case XPATH_OP_NODE:
if (op->ch1 != -1)
total += xmlXPathCompOpEval(ctxt, &comp->steps[op->ch1]);
@@ -13580,7 +13588,7 @@ xmlXPathCompOpEval(xmlXPathParserContext
CHECK_ERROR0;
valuePush(ctxt, xmlXPathCacheNewNodeSet(ctxt->context,
ctxt->context->node));
- return (total);
+ break;
case XPATH_OP_RESET:
if (op->ch1 != -1)
total += xmlXPathCompOpEval(ctxt, &comp->steps[op->ch1]);
@@ -13589,22 +13597,22 @@ xmlXPathCompOpEval(xmlXPathParserContext
total += xmlXPathCompOpEval(ctxt, &comp->steps[op->ch2]);
CHECK_ERROR0;
ctxt->context->node = NULL;
- return (total);
+ break;
case XPATH_OP_COLLECT:{
if (op->ch1 == -1)
- return (total);
+ break;
total += xmlXPathCompOpEval(ctxt, &comp->steps[op->ch1]);
CHECK_ERROR0;
total += xmlXPathNodeCollectAndTest(ctxt, op, NULL, NULL, 0);
- return (total);
+ break;
}
case XPATH_OP_VALUE:
valuePush(ctxt,
xmlXPathCacheObjectCopy(ctxt->context,
(xmlXPathObjectPtr) op->value4));
- return (total);
+ break;
case XPATH_OP_VARIABLE:{
xmlXPathObjectPtr val;
@@ -13625,7 +13633,7 @@ xmlXPathCompOpEval(xmlXPathParserContext
"xmlXPathCompOpEval: variable %s bound to undefined prefix %s\n",
(char *) op->value4, (char *)op->value5);
ctxt->error = XPATH_UNDEF_PREFIX_ERROR;
- return (total);
+ break;
}
val = xmlXPathVariableLookupNS(ctxt->context,
op->value4, URI);
@@ -13633,7 +13641,7 @@ xmlXPathCompOpEval(xmlXPathParserContext
XP_ERROR0(XPATH_UNDEF_VARIABLE_ERROR);
valuePush(ctxt, val);
}
- return (total);
+ break;
}
case XPATH_OP_FUNCTION:{
xmlXPathFunction func;
@@ -13647,7 +13655,7 @@ xmlXPathCompOpEval(xmlXPathParserContext
xmlXPathCompOpEval(ctxt, &comp->steps[op->ch1]);
if (ctxt->error != XPATH_EXPRESSION_OK) {
xmlXPathPopFrame(ctxt, frame);
- return (total);
+ break;
}
}
if (ctxt->valueNr < ctxt->valueFrame + op->value) {
@@ -13655,7 +13663,7 @@ xmlXPathCompOpEval(xmlXPathParserContext
"xmlXPathCompOpEval: parameter error\n");
ctxt->error = XPATH_INVALID_OPERAND;
xmlXPathPopFrame(ctxt, frame);
- return (total);
+ break;
}
for (i = 0; i < op->value; i++) {
if (ctxt->valueTab[(ctxt->valueNr - 1) - i] == NULL) {
@@ -13663,7 +13671,7 @@ xmlXPathCompOpEval(xmlXPathParserContext
"xmlXPathCompOpEval: parameter error\n");
ctxt->error = XPATH_INVALID_OPERAND;
xmlXPathPopFrame(ctxt, frame);
- return (total);
+ break;
}
}
if (op->cache != NULL)
@@ -13683,7 +13691,7 @@ xmlXPathCompOpEval(xmlXPathParserContext
(char *)op->value4, (char *)op->value5);
xmlXPathPopFrame(ctxt, frame);
ctxt->error = XPATH_UNDEF_PREFIX_ERROR;
- return (total);
+ break;
}
func = xmlXPathFunctionLookupNS(ctxt->context,
op->value4, URI);
@@ -13705,7 +13713,7 @@ xmlXPathCompOpEval(xmlXPathParserContext
ctxt->context->function = oldFunc;
ctxt->context->functionURI = oldFuncURI;
xmlXPathPopFrame(ctxt, frame);
- return (total);
+ break;
}
case XPATH_OP_ARG:
bakd = ctxt->context->doc;
@@ -13728,7 +13736,7 @@ xmlXPathCompOpEval(xmlXPathParserContext
ctxt->context->doc = bakd;
CHECK_ERROR0;
}
- return (total);
+ break;
case XPATH_OP_PREDICATE:
case XPATH_OP_FILTER:{
xmlXPathObjectPtr res;
@@ -13781,7 +13789,7 @@ xmlXPathCompOpEval(xmlXPathParserContext
(ctxt->value->nodesetval->nodeNr > 1))
xmlXPathNodeSetClearFromPos(ctxt->value->nodesetval,
1, 1);
- return (total);
+ break;
}
}
/*
@@ -13816,7 +13824,7 @@ xmlXPathCompOpEval(xmlXPathParserContext
(ctxt->value->nodesetval->nodeTab != NULL) &&
(ctxt->value->nodesetval->nodeNr > 1))
xmlXPathNodeSetKeepLast(ctxt->value->nodesetval);
- return (total);
+ break;
}
}
/*
@@ -13835,9 +13843,9 @@ xmlXPathCompOpEval(xmlXPathParserContext
xmlXPathCompOpEval(ctxt, &comp->steps[op->ch1]);
CHECK_ERROR0;
if (op->ch2 == -1)
- return (total);
+ break;
if (ctxt->value == NULL)
- return (total);
+ break;
oldnode = ctxt->context->node;
@@ -13872,7 +13880,7 @@ xmlXPathCompOpEval(xmlXPathParserContext
}
valuePush(ctxt, obj);
CHECK_ERROR0;
- return (total);
+ break;
}
newlocset = xmlXPtrLocationSetCreate(NULL);
@@ -13894,7 +13902,7 @@ xmlXPathCompOpEval(xmlXPathParserContext
&comp->steps[op->ch2]);
if (ctxt->error != XPATH_EXPRESSION_OK) {
xmlXPathFreeObject(obj);
- return(0);
+ break;
}
/*
@@ -13931,7 +13939,7 @@ xmlXPathCompOpEval(xmlXPathParserContext
ctxt->context->proximityPosition = -1;
valuePush(ctxt, xmlXPtrWrapLocationSet(newlocset));
ctxt->context->node = oldnode;
- return (total);
+ break;
}
#endif /* LIBXML_XPTR_ENABLED */
@@ -14031,7 +14039,7 @@ xmlXPathCompOpEval(xmlXPathParserContext
if (ctxt->error != XPATH_EXPRESSION_OK) {
xmlXPathFreeNodeSet(newset);
xmlXPathFreeObject(obj);
- return(0);
+ break;
}
/*
@@ -14082,7 +14090,7 @@ xmlXPathCompOpEval(xmlXPathParserContext
xmlXPathCacheWrapNodeSet(ctxt->context, newset));
}
ctxt->context->node = oldnode;
- return (total);
+ break;
}
case XPATH_OP_SORT:
if (op->ch1 != -1)
@@ -14095,7 +14103,7 @@ xmlXPathCompOpEval(xmlXPathParserContext
{
xmlXPathNodeSetSort(ctxt->value->nodesetval);
}
- return (total);
+ break;
#ifdef LIBXML_XPTR_ENABLED
case XPATH_OP_RANGETO:{
xmlXPathObjectPtr range;
@@ -14115,7 +14123,7 @@ xmlXPathCompOpEval(xmlXPathParserContext
XP_ERROR0(XPATH_INVALID_OPERAND);
}
if (op->ch2 == -1)
- return (total);
+ break;
if (ctxt->value->type == XPATH_LOCATIONSET) {
/*
@@ -14138,7 +14146,7 @@ xmlXPathCompOpEval(xmlXPathParserContext
}
valuePush(ctxt, obj);
CHECK_ERROR0;
- return (total);
+ break;
}
newlocset = xmlXPtrLocationSetCreate(NULL);
@@ -14160,7 +14168,7 @@ xmlXPathCompOpEval(xmlXPathParserContext
&comp->steps[op->ch2]);
if (ctxt->error != XPATH_EXPRESSION_OK) {
xmlXPathFreeObject(obj);
- return(0);
+ break;
}
res = valuePop(ctxt);
@@ -14226,7 +14234,7 @@ xmlXPathCompOpEval(xmlXPathParserContext
&comp->steps[op->ch2]);
if (ctxt->error != XPATH_EXPRESSION_OK) {
xmlXPathFreeObject(obj);
- return(0);
+ break;
}
res = valuePop(ctxt);
@@ -14261,13 +14269,16 @@ xmlXPathCompOpEval(xmlXPathParserContext
ctxt->context->contextSize = -1;
ctxt->context->proximityPosition = -1;
valuePush(ctxt, xmlXPtrWrapLocationSet(newlocset));
- return (total);
+ break;
}
#endif /* LIBXML_XPTR_ENABLED */
+ default:
+ xmlGenericError(xmlGenericErrorContext,
+ "XPath: unknown precompiled operation %d\n", op->op);
+ ctxt->error = XPATH_INVALID_OPERAND;
+ break;
}
- xmlGenericError(xmlGenericErrorContext,
- "XPath: unknown precompiled operation %d\n", op->op);
- ctxt->error = XPATH_INVALID_OPERAND;
+
return (total);
}