File libxml2-CVE-2025-9714-1.patch of Package libxml2.41581

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.4/xpath.c
===================================================================
--- libxml2-2.9.4.orig/xpath.c
+++ libxml2-2.9.4/xpath.c
@@ -12794,7 +12794,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],
@@ -12836,7 +12836,7 @@ xmlXPathCompOpEvalFirst(xmlXPathParserCo
                                         arg2->nodesetval->nodeNr) < 0)))) {
 	        xmlXPathReleaseObject(ctxt->context, arg1);
 	        xmlXPathReleaseObject(ctxt->context, arg2);
-                return(0);
+                break;
             }
 
             arg1->nodesetval = xmlXPathNodeSetMerge(arg1->nodesetval,
@@ -12846,10 +12846,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]);
@@ -12859,7 +12860,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]);
@@ -12868,22 +12869,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 +=
@@ -12895,15 +12896,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);
 }
 
 /**
@@ -12935,7 +12939,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;
@@ -12984,7 +12988,7 @@ xmlXPathCompOpEvalLast(xmlXPathParserCon
                                         arg2->nodesetval->nodeNr) < 0)))) {
 	        xmlXPathReleaseObject(ctxt->context, arg1);
 	        xmlXPathReleaseObject(ctxt->context, arg2);
-                return(0);
+                break;
             }
 
             arg1->nodesetval = xmlXPathNodeSetMerge(arg1->nodesetval,
@@ -12994,10 +12998,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]);
@@ -13007,7 +13012,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]);
@@ -13016,22 +13021,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 +=
@@ -13043,10 +13048,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
@@ -13374,7 +13382,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;
@@ -13384,7 +13392,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;
@@ -13393,13 +13401,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;
@@ -13409,7 +13417,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;
@@ -13418,13 +13426,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;
@@ -13443,7 +13451,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;
@@ -13459,7 +13467,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;
@@ -13485,7 +13493,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;
@@ -13505,7 +13513,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;
@@ -13533,7 +13541,7 @@ xmlXPathCompOpEval(xmlXPathParserContext
                                         arg2->nodesetval->nodeNr) < 0)))) {
 	        xmlXPathReleaseObject(ctxt->context, arg1);
 	        xmlXPathReleaseObject(ctxt->context, arg2);
-                return(0);
+                break;
             }
 
 	    if ((arg1->nodesetval == NULL) ||
@@ -13546,10 +13554,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]);
@@ -13559,7 +13567,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]);
@@ -13568,22 +13576,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;
 
@@ -13594,7 +13602,7 @@ xmlXPathCompOpEval(xmlXPathParserContext
 		    val = xmlXPathVariableLookup(ctxt->context, op->value4);
 		    if (val == NULL) {
 			ctxt->error = XPATH_UNDEF_VARIABLE_ERROR;
-			return(0);
+			break;
 		    }
                     valuePush(ctxt, val);
 		} else {
@@ -13606,17 +13614,17 @@ 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);
 		    if (val == NULL) {
 			ctxt->error = XPATH_UNDEF_VARIABLE_ERROR;
-			return(0);
+			break;
 		    }
                     valuePush(ctxt, val);
                 }
-                return (total);
+                break;
             }
         case XPATH_OP_FUNCTION:{
                 xmlXPathFunction func;
@@ -13630,7 +13638,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) {
@@ -13638,7 +13646,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) {
@@ -13646,7 +13654,7 @@ xmlXPathCompOpEval(xmlXPathParserContext
 				"xmlXPathCompOpEval: parameter error\n");
 			ctxt->error = XPATH_INVALID_OPERAND;
                         xmlXPathPopFrame(ctxt, frame);
-			return (total);
+			break;
 		    }
                 }
                 if (op->cache != NULL)
@@ -13666,7 +13674,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);
@@ -13688,7 +13696,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;
@@ -13711,7 +13719,7 @@ xmlXPathCompOpEval(xmlXPathParserContext
                 ctxt->context->doc = bakd;
 	        CHECK_ERROR0;
 	    }
-            return (total);
+            break;
         case XPATH_OP_PREDICATE:
         case XPATH_OP_FILTER:{
                 xmlXPathObjectPtr res;
@@ -13763,7 +13771,7 @@ xmlXPathCompOpEval(xmlXPathParserContext
                             (ctxt->value->nodesetval != NULL) &&
                             (ctxt->value->nodesetval->nodeNr > 1))
                             ctxt->value->nodesetval->nodeNr = 1;
-                        return (total);
+                        break;
                     }
                 }
                 /*
@@ -13805,7 +13813,7 @@ xmlXPathCompOpEval(xmlXPathParserContext
                                                                  1];
                             ctxt->value->nodesetval->nodeNr = 1;
                         }
-                        return (total);
+                        break;
                     }
                 }
 		/*
@@ -13824,9 +13832,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;
 
@@ -13861,7 +13869,7 @@ xmlXPathCompOpEval(xmlXPathParserContext
 			}
                         valuePush(ctxt, obj);
                         CHECK_ERROR0;
-                        return (total);
+                        break;
                     }
                     newlocset = xmlXPtrLocationSetCreate(NULL);
 
@@ -13883,7 +13891,7 @@ xmlXPathCompOpEval(xmlXPathParserContext
                                                    &comp->steps[op->ch2]);
 			if (ctxt->error != XPATH_EXPRESSION_OK) {
 			    xmlXPathFreeObject(obj);
-			    return(0);
+			    break;
 			}
 
                         /*
@@ -13920,7 +13928,7 @@ xmlXPathCompOpEval(xmlXPathParserContext
                     ctxt->context->proximityPosition = -1;
                     valuePush(ctxt, xmlXPtrWrapLocationSet(newlocset));
                     ctxt->context->node = oldnode;
-                    return (total);
+                    break;
                 }
 #endif /* LIBXML_XPTR_ENABLED */
 
@@ -14020,7 +14028,7 @@ xmlXPathCompOpEval(xmlXPathParserContext
 			if (ctxt->error != XPATH_EXPRESSION_OK) {
 			    xmlXPathFreeNodeSet(newset);
 			    xmlXPathFreeObject(obj);
-			    return(0);
+			    break;
 			}
 
                         /*
@@ -14071,7 +14079,7 @@ xmlXPathCompOpEval(xmlXPathParserContext
 			xmlXPathCacheWrapNodeSet(ctxt->context, newset));
                 }
                 ctxt->context->node = oldnode;
-                return (total);
+                break;
             }
         case XPATH_OP_SORT:
             if (op->ch1 != -1)
@@ -14084,7 +14092,7 @@ xmlXPathCompOpEval(xmlXPathParserContext
 	    {
                 xmlXPathNodeSetSort(ctxt->value->nodesetval);
 	    }
-            return (total);
+            break;
 #ifdef LIBXML_XPTR_ENABLED
         case XPATH_OP_RANGETO:{
                 xmlXPathObjectPtr range;
@@ -14099,7 +14107,7 @@ xmlXPathCompOpEval(xmlXPathParserContext
                     total +=
                         xmlXPathCompOpEval(ctxt, &comp->steps[op->ch1]);
                 if (op->ch2 == -1)
-                    return (total);
+                    break;
 
                 if (ctxt->value->type == XPATH_LOCATIONSET) {
                     /*
@@ -14122,7 +14130,7 @@ xmlXPathCompOpEval(xmlXPathParserContext
 			}
                         valuePush(ctxt, obj);
                         CHECK_ERROR0;
-                        return (total);
+                        break;
                     }
                     newlocset = xmlXPtrLocationSetCreate(NULL);
 
@@ -14144,7 +14152,7 @@ xmlXPathCompOpEval(xmlXPathParserContext
                                                    &comp->steps[op->ch2]);
 			if (ctxt->error != XPATH_EXPRESSION_OK) {
 			    xmlXPathFreeObject(obj);
-			    return(0);
+			    break;
 			}
 
                         res = valuePop(ctxt);
@@ -14210,7 +14218,7 @@ xmlXPathCompOpEval(xmlXPathParserContext
                                                    &comp->steps[op->ch2]);
 			    if (ctxt->error != XPATH_EXPRESSION_OK) {
 				xmlXPathFreeObject(obj);
-				return(0);
+				break;
 			    }
 
                             res = valuePop(ctxt);
@@ -14245,13 +14253,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);
 }
 
openSUSE Build Service is sponsored by