mirror of
https://gitlab.gnome.org/GNOME/libxml2.git
synced 2025-07-29 11:41:22 +03:00
trying to harden the XPath interpreter Daniel
* xpath.c: trying to harden the XPath interpreter Daniel
This commit is contained in:
@ -1,3 +1,7 @@
|
|||||||
|
Sat Oct 6 11:58:58 CEST 2001 Daniel Veillard <daniel@veillard.com>
|
||||||
|
|
||||||
|
* xpath.c: trying to harden the XPath interpreter
|
||||||
|
|
||||||
Fri Oct 5 20:37:51 MDT 2001 John Fleck <jfleck@inkstain.net>
|
Fri Oct 5 20:37:51 MDT 2001 John Fleck <jfleck@inkstain.net>
|
||||||
|
|
||||||
* doc/xmlcatalog.1 updated using a new stylesheet to address, in
|
* doc/xmlcatalog.1 updated using a new stylesheet to address, in
|
||||||
|
92
xpath.c
92
xpath.c
@ -2421,7 +2421,7 @@ xmlXPathVariableLookup(xmlXPathContextPtr ctxt, const xmlChar *name) {
|
|||||||
|
|
||||||
ret = ((xmlXPathVariableLookupFunc)ctxt->varLookupFunc)
|
ret = ((xmlXPathVariableLookupFunc)ctxt->varLookupFunc)
|
||||||
(ctxt->varLookupData, name, NULL);
|
(ctxt->varLookupData, name, NULL);
|
||||||
if (ret != NULL) return(ret);
|
return(ret);
|
||||||
}
|
}
|
||||||
return(xmlXPathVariableLookupNS(ctxt, name, NULL));
|
return(xmlXPathVariableLookupNS(ctxt, name, NULL));
|
||||||
}
|
}
|
||||||
@ -8769,6 +8769,7 @@ xmlXPathCompOpEvalFirst(xmlXPathParserContextPtr ctxt,
|
|||||||
xmlXPathCompExprPtr comp;
|
xmlXPathCompExprPtr comp;
|
||||||
xmlXPathObjectPtr arg1, arg2;
|
xmlXPathObjectPtr arg1, arg2;
|
||||||
|
|
||||||
|
CHECK_ERROR0;
|
||||||
comp = ctxt->comp;
|
comp = ctxt->comp;
|
||||||
switch (op->op) {
|
switch (op->op) {
|
||||||
case XPATH_OP_END:
|
case XPATH_OP_END:
|
||||||
@ -8777,6 +8778,7 @@ xmlXPathCompOpEvalFirst(xmlXPathParserContextPtr ctxt,
|
|||||||
total =
|
total =
|
||||||
xmlXPathCompOpEvalFirst(ctxt, &comp->steps[op->ch1],
|
xmlXPathCompOpEvalFirst(ctxt, &comp->steps[op->ch1],
|
||||||
first);
|
first);
|
||||||
|
CHECK_ERROR0;
|
||||||
if ((ctxt->value != NULL)
|
if ((ctxt->value != NULL)
|
||||||
&& (ctxt->value->type == XPATH_NODESET)
|
&& (ctxt->value->type == XPATH_NODESET)
|
||||||
&& (ctxt->value->nodesetval != NULL)
|
&& (ctxt->value->nodesetval != NULL)
|
||||||
@ -8790,6 +8792,7 @@ xmlXPathCompOpEvalFirst(xmlXPathParserContextPtr ctxt,
|
|||||||
cur =
|
cur =
|
||||||
xmlXPathCompOpEvalFirst(ctxt, &comp->steps[op->ch2],
|
xmlXPathCompOpEvalFirst(ctxt, &comp->steps[op->ch2],
|
||||||
first);
|
first);
|
||||||
|
CHECK_ERROR0;
|
||||||
CHECK_TYPE0(XPATH_NODESET);
|
CHECK_TYPE0(XPATH_NODESET);
|
||||||
arg2 = valuePop(ctxt);
|
arg2 = valuePop(ctxt);
|
||||||
|
|
||||||
@ -8810,15 +8813,19 @@ xmlXPathCompOpEvalFirst(xmlXPathParserContextPtr ctxt,
|
|||||||
case XPATH_OP_NODE:
|
case XPATH_OP_NODE:
|
||||||
if (op->ch1 != -1)
|
if (op->ch1 != -1)
|
||||||
total += xmlXPathCompOpEval(ctxt, &comp->steps[op->ch1]);
|
total += xmlXPathCompOpEval(ctxt, &comp->steps[op->ch1]);
|
||||||
|
CHECK_ERROR0;
|
||||||
if (op->ch2 != -1)
|
if (op->ch2 != -1)
|
||||||
total += xmlXPathCompOpEval(ctxt, &comp->steps[op->ch2]);
|
total += xmlXPathCompOpEval(ctxt, &comp->steps[op->ch2]);
|
||||||
|
CHECK_ERROR0;
|
||||||
valuePush(ctxt, xmlXPathNewNodeSet(ctxt->context->node));
|
valuePush(ctxt, xmlXPathNewNodeSet(ctxt->context->node));
|
||||||
return (total);
|
return (total);
|
||||||
case XPATH_OP_RESET:
|
case XPATH_OP_RESET:
|
||||||
if (op->ch1 != -1)
|
if (op->ch1 != -1)
|
||||||
total += xmlXPathCompOpEval(ctxt, &comp->steps[op->ch1]);
|
total += xmlXPathCompOpEval(ctxt, &comp->steps[op->ch1]);
|
||||||
|
CHECK_ERROR0;
|
||||||
if (op->ch2 != -1)
|
if (op->ch2 != -1)
|
||||||
total += xmlXPathCompOpEval(ctxt, &comp->steps[op->ch2]);
|
total += xmlXPathCompOpEval(ctxt, &comp->steps[op->ch2]);
|
||||||
|
CHECK_ERROR0;
|
||||||
ctxt->context->node = NULL;
|
ctxt->context->node = NULL;
|
||||||
return (total);
|
return (total);
|
||||||
case XPATH_OP_COLLECT:{
|
case XPATH_OP_COLLECT:{
|
||||||
@ -8826,6 +8833,7 @@ xmlXPathCompOpEvalFirst(xmlXPathParserContextPtr ctxt,
|
|||||||
return (total);
|
return (total);
|
||||||
|
|
||||||
total = xmlXPathCompOpEval(ctxt, &comp->steps[op->ch1]);
|
total = xmlXPathCompOpEval(ctxt, &comp->steps[op->ch1]);
|
||||||
|
CHECK_ERROR0;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Optimization for [n] selection where n is a number
|
* Optimization for [n] selection where n is a number
|
||||||
@ -8861,6 +8869,7 @@ xmlXPathCompOpEvalFirst(xmlXPathParserContextPtr ctxt,
|
|||||||
total +=
|
total +=
|
||||||
xmlXPathCompOpEvalFirst(ctxt, &comp->steps[op->ch1],
|
xmlXPathCompOpEvalFirst(ctxt, &comp->steps[op->ch1],
|
||||||
first);
|
first);
|
||||||
|
CHECK_ERROR0;
|
||||||
if ((ctxt->value != NULL)
|
if ((ctxt->value != NULL)
|
||||||
&& (ctxt->value->type == XPATH_NODESET)
|
&& (ctxt->value->type == XPATH_NODESET)
|
||||||
&& (ctxt->value->nodesetval != NULL))
|
&& (ctxt->value->nodesetval != NULL))
|
||||||
@ -8890,6 +8899,7 @@ xmlXPathCompOpEvalLast(xmlXPathParserContextPtr ctxt, xmlXPathStepOpPtr op,
|
|||||||
xmlXPathCompExprPtr comp;
|
xmlXPathCompExprPtr comp;
|
||||||
xmlXPathObjectPtr arg1, arg2;
|
xmlXPathObjectPtr arg1, arg2;
|
||||||
|
|
||||||
|
CHECK_ERROR0;
|
||||||
comp = ctxt->comp;
|
comp = ctxt->comp;
|
||||||
switch (op->op) {
|
switch (op->op) {
|
||||||
case XPATH_OP_END:
|
case XPATH_OP_END:
|
||||||
@ -8897,6 +8907,7 @@ xmlXPathCompOpEvalLast(xmlXPathParserContextPtr ctxt, xmlXPathStepOpPtr op,
|
|||||||
case XPATH_OP_UNION:
|
case XPATH_OP_UNION:
|
||||||
total =
|
total =
|
||||||
xmlXPathCompOpEvalLast(ctxt, &comp->steps[op->ch1], last);
|
xmlXPathCompOpEvalLast(ctxt, &comp->steps[op->ch1], last);
|
||||||
|
CHECK_ERROR0;
|
||||||
if ((ctxt->value != NULL)
|
if ((ctxt->value != NULL)
|
||||||
&& (ctxt->value->type == XPATH_NODESET)
|
&& (ctxt->value->type == XPATH_NODESET)
|
||||||
&& (ctxt->value->nodesetval != NULL)
|
&& (ctxt->value->nodesetval != NULL)
|
||||||
@ -8912,6 +8923,7 @@ xmlXPathCompOpEvalLast(xmlXPathParserContextPtr ctxt, xmlXPathStepOpPtr op,
|
|||||||
}
|
}
|
||||||
cur =
|
cur =
|
||||||
xmlXPathCompOpEvalLast(ctxt, &comp->steps[op->ch2], last);
|
xmlXPathCompOpEvalLast(ctxt, &comp->steps[op->ch2], last);
|
||||||
|
CHECK_ERROR0;
|
||||||
if ((ctxt->value != NULL)
|
if ((ctxt->value != NULL)
|
||||||
&& (ctxt->value->type == XPATH_NODESET)
|
&& (ctxt->value->type == XPATH_NODESET)
|
||||||
&& (ctxt->value->nodesetval != NULL)
|
&& (ctxt->value->nodesetval != NULL)
|
||||||
@ -8937,15 +8949,19 @@ xmlXPathCompOpEvalLast(xmlXPathParserContextPtr ctxt, xmlXPathStepOpPtr op,
|
|||||||
case XPATH_OP_NODE:
|
case XPATH_OP_NODE:
|
||||||
if (op->ch1 != -1)
|
if (op->ch1 != -1)
|
||||||
total += xmlXPathCompOpEval(ctxt, &comp->steps[op->ch1]);
|
total += xmlXPathCompOpEval(ctxt, &comp->steps[op->ch1]);
|
||||||
|
CHECK_ERROR0;
|
||||||
if (op->ch2 != -1)
|
if (op->ch2 != -1)
|
||||||
total += xmlXPathCompOpEval(ctxt, &comp->steps[op->ch2]);
|
total += xmlXPathCompOpEval(ctxt, &comp->steps[op->ch2]);
|
||||||
|
CHECK_ERROR0;
|
||||||
valuePush(ctxt, xmlXPathNewNodeSet(ctxt->context->node));
|
valuePush(ctxt, xmlXPathNewNodeSet(ctxt->context->node));
|
||||||
return (total);
|
return (total);
|
||||||
case XPATH_OP_RESET:
|
case XPATH_OP_RESET:
|
||||||
if (op->ch1 != -1)
|
if (op->ch1 != -1)
|
||||||
total += xmlXPathCompOpEval(ctxt, &comp->steps[op->ch1]);
|
total += xmlXPathCompOpEval(ctxt, &comp->steps[op->ch1]);
|
||||||
|
CHECK_ERROR0;
|
||||||
if (op->ch2 != -1)
|
if (op->ch2 != -1)
|
||||||
total += xmlXPathCompOpEval(ctxt, &comp->steps[op->ch2]);
|
total += xmlXPathCompOpEval(ctxt, &comp->steps[op->ch2]);
|
||||||
|
CHECK_ERROR0;
|
||||||
ctxt->context->node = NULL;
|
ctxt->context->node = NULL;
|
||||||
return (total);
|
return (total);
|
||||||
case XPATH_OP_COLLECT:{
|
case XPATH_OP_COLLECT:{
|
||||||
@ -8953,6 +8969,7 @@ xmlXPathCompOpEvalLast(xmlXPathParserContextPtr ctxt, xmlXPathStepOpPtr op,
|
|||||||
return (0);
|
return (0);
|
||||||
|
|
||||||
total += xmlXPathCompOpEval(ctxt, &comp->steps[op->ch1]);
|
total += xmlXPathCompOpEval(ctxt, &comp->steps[op->ch1]);
|
||||||
|
CHECK_ERROR0;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Optimization for [n] selection where n is a number
|
* Optimization for [n] selection where n is a number
|
||||||
@ -8990,6 +9007,7 @@ xmlXPathCompOpEvalLast(xmlXPathParserContextPtr ctxt, xmlXPathStepOpPtr op,
|
|||||||
total +=
|
total +=
|
||||||
xmlXPathCompOpEvalLast(ctxt, &comp->steps[op->ch1],
|
xmlXPathCompOpEvalLast(ctxt, &comp->steps[op->ch1],
|
||||||
last);
|
last);
|
||||||
|
CHECK_ERROR0;
|
||||||
if ((ctxt->value != NULL)
|
if ((ctxt->value != NULL)
|
||||||
&& (ctxt->value->type == XPATH_NODESET)
|
&& (ctxt->value->type == XPATH_NODESET)
|
||||||
&& (ctxt->value->nodesetval != NULL))
|
&& (ctxt->value->nodesetval != NULL))
|
||||||
@ -9016,17 +9034,23 @@ xmlXPathCompOpEval(xmlXPathParserContextPtr ctxt, xmlXPathStepOpPtr op)
|
|||||||
xmlXPathCompExprPtr comp;
|
xmlXPathCompExprPtr comp;
|
||||||
xmlXPathObjectPtr arg1, arg2;
|
xmlXPathObjectPtr arg1, arg2;
|
||||||
|
|
||||||
|
CHECK_ERROR0;
|
||||||
comp = ctxt->comp;
|
comp = ctxt->comp;
|
||||||
switch (op->op) {
|
switch (op->op) {
|
||||||
case XPATH_OP_END:
|
case XPATH_OP_END:
|
||||||
return (0);
|
return (0);
|
||||||
case XPATH_OP_AND:
|
case XPATH_OP_AND:
|
||||||
total += xmlXPathCompOpEval(ctxt, &comp->steps[op->ch1]);
|
total += xmlXPathCompOpEval(ctxt, &comp->steps[op->ch1]);
|
||||||
|
CHECK_ERROR0;
|
||||||
xmlXPathBooleanFunction(ctxt, 1);
|
xmlXPathBooleanFunction(ctxt, 1);
|
||||||
if ((ctxt->value == NULL) || (ctxt->value->boolval == 0))
|
if ((ctxt->value == NULL) || (ctxt->value->boolval == 0))
|
||||||
return (total);
|
return (total);
|
||||||
arg2 = valuePop(ctxt);
|
arg2 = valuePop(ctxt);
|
||||||
total += xmlXPathCompOpEval(ctxt, &comp->steps[op->ch2]);
|
total += xmlXPathCompOpEval(ctxt, &comp->steps[op->ch2]);
|
||||||
|
if (ctxt->error) {
|
||||||
|
xmlXPathFreeObject(arg2);
|
||||||
|
return(0);
|
||||||
|
}
|
||||||
xmlXPathBooleanFunction(ctxt, 1);
|
xmlXPathBooleanFunction(ctxt, 1);
|
||||||
arg1 = valuePop(ctxt);
|
arg1 = valuePop(ctxt);
|
||||||
arg1->boolval &= arg2->boolval;
|
arg1->boolval &= arg2->boolval;
|
||||||
@ -9035,11 +9059,16 @@ xmlXPathCompOpEval(xmlXPathParserContextPtr ctxt, xmlXPathStepOpPtr op)
|
|||||||
return (total);
|
return (total);
|
||||||
case XPATH_OP_OR:
|
case XPATH_OP_OR:
|
||||||
total += xmlXPathCompOpEval(ctxt, &comp->steps[op->ch1]);
|
total += xmlXPathCompOpEval(ctxt, &comp->steps[op->ch1]);
|
||||||
|
CHECK_ERROR0;
|
||||||
xmlXPathBooleanFunction(ctxt, 1);
|
xmlXPathBooleanFunction(ctxt, 1);
|
||||||
if ((ctxt->value == NULL) || (ctxt->value->boolval == 1))
|
if ((ctxt->value == NULL) || (ctxt->value->boolval == 1))
|
||||||
return (total);
|
return (total);
|
||||||
arg2 = valuePop(ctxt);
|
arg2 = valuePop(ctxt);
|
||||||
total += xmlXPathCompOpEval(ctxt, &comp->steps[op->ch2]);
|
total += xmlXPathCompOpEval(ctxt, &comp->steps[op->ch2]);
|
||||||
|
if (ctxt->error) {
|
||||||
|
xmlXPathFreeObject(arg2);
|
||||||
|
return(0);
|
||||||
|
}
|
||||||
xmlXPathBooleanFunction(ctxt, 1);
|
xmlXPathBooleanFunction(ctxt, 1);
|
||||||
arg1 = valuePop(ctxt);
|
arg1 = valuePop(ctxt);
|
||||||
arg1->boolval |= arg2->boolval;
|
arg1->boolval |= arg2->boolval;
|
||||||
@ -9048,7 +9077,9 @@ xmlXPathCompOpEval(xmlXPathParserContextPtr ctxt, xmlXPathStepOpPtr op)
|
|||||||
return (total);
|
return (total);
|
||||||
case XPATH_OP_EQUAL:
|
case XPATH_OP_EQUAL:
|
||||||
total += xmlXPathCompOpEval(ctxt, &comp->steps[op->ch1]);
|
total += xmlXPathCompOpEval(ctxt, &comp->steps[op->ch1]);
|
||||||
|
CHECK_ERROR0;
|
||||||
total += xmlXPathCompOpEval(ctxt, &comp->steps[op->ch2]);
|
total += xmlXPathCompOpEval(ctxt, &comp->steps[op->ch2]);
|
||||||
|
CHECK_ERROR0;
|
||||||
equal = xmlXPathEqualValues(ctxt);
|
equal = xmlXPathEqualValues(ctxt);
|
||||||
if (op->value)
|
if (op->value)
|
||||||
valuePush(ctxt, xmlXPathNewBoolean(equal));
|
valuePush(ctxt, xmlXPathNewBoolean(equal));
|
||||||
@ -9057,14 +9088,18 @@ xmlXPathCompOpEval(xmlXPathParserContextPtr ctxt, xmlXPathStepOpPtr op)
|
|||||||
return (total);
|
return (total);
|
||||||
case XPATH_OP_CMP:
|
case XPATH_OP_CMP:
|
||||||
total += xmlXPathCompOpEval(ctxt, &comp->steps[op->ch1]);
|
total += xmlXPathCompOpEval(ctxt, &comp->steps[op->ch1]);
|
||||||
|
CHECK_ERROR0;
|
||||||
total += xmlXPathCompOpEval(ctxt, &comp->steps[op->ch2]);
|
total += xmlXPathCompOpEval(ctxt, &comp->steps[op->ch2]);
|
||||||
|
CHECK_ERROR0;
|
||||||
ret = xmlXPathCompareValues(ctxt, op->value, op->value2);
|
ret = xmlXPathCompareValues(ctxt, op->value, op->value2);
|
||||||
valuePush(ctxt, xmlXPathNewBoolean(ret));
|
valuePush(ctxt, xmlXPathNewBoolean(ret));
|
||||||
return (total);
|
return (total);
|
||||||
case XPATH_OP_PLUS:
|
case XPATH_OP_PLUS:
|
||||||
total += xmlXPathCompOpEval(ctxt, &comp->steps[op->ch1]);
|
total += xmlXPathCompOpEval(ctxt, &comp->steps[op->ch1]);
|
||||||
|
CHECK_ERROR0;
|
||||||
if (op->ch2 != -1)
|
if (op->ch2 != -1)
|
||||||
total += xmlXPathCompOpEval(ctxt, &comp->steps[op->ch2]);
|
total += xmlXPathCompOpEval(ctxt, &comp->steps[op->ch2]);
|
||||||
|
CHECK_ERROR0;
|
||||||
if (op->value == 0)
|
if (op->value == 0)
|
||||||
xmlXPathSubValues(ctxt);
|
xmlXPathSubValues(ctxt);
|
||||||
else if (op->value == 1)
|
else if (op->value == 1)
|
||||||
@ -9078,7 +9113,9 @@ xmlXPathCompOpEval(xmlXPathParserContextPtr ctxt, xmlXPathStepOpPtr op)
|
|||||||
return (total);
|
return (total);
|
||||||
case XPATH_OP_MULT:
|
case XPATH_OP_MULT:
|
||||||
total += xmlXPathCompOpEval(ctxt, &comp->steps[op->ch1]);
|
total += xmlXPathCompOpEval(ctxt, &comp->steps[op->ch1]);
|
||||||
|
CHECK_ERROR0;
|
||||||
total += xmlXPathCompOpEval(ctxt, &comp->steps[op->ch2]);
|
total += xmlXPathCompOpEval(ctxt, &comp->steps[op->ch2]);
|
||||||
|
CHECK_ERROR0;
|
||||||
if (op->value == 0)
|
if (op->value == 0)
|
||||||
xmlXPathMultValues(ctxt);
|
xmlXPathMultValues(ctxt);
|
||||||
else if (op->value == 1)
|
else if (op->value == 1)
|
||||||
@ -9088,7 +9125,9 @@ xmlXPathCompOpEval(xmlXPathParserContextPtr ctxt, xmlXPathStepOpPtr op)
|
|||||||
return (total);
|
return (total);
|
||||||
case XPATH_OP_UNION:
|
case XPATH_OP_UNION:
|
||||||
total += xmlXPathCompOpEval(ctxt, &comp->steps[op->ch1]);
|
total += xmlXPathCompOpEval(ctxt, &comp->steps[op->ch1]);
|
||||||
|
CHECK_ERROR0;
|
||||||
total += xmlXPathCompOpEval(ctxt, &comp->steps[op->ch2]);
|
total += xmlXPathCompOpEval(ctxt, &comp->steps[op->ch2]);
|
||||||
|
CHECK_ERROR0;
|
||||||
CHECK_TYPE0(XPATH_NODESET);
|
CHECK_TYPE0(XPATH_NODESET);
|
||||||
arg2 = valuePop(ctxt);
|
arg2 = valuePop(ctxt);
|
||||||
|
|
||||||
@ -9106,15 +9145,19 @@ xmlXPathCompOpEval(xmlXPathParserContextPtr ctxt, xmlXPathStepOpPtr op)
|
|||||||
case XPATH_OP_NODE:
|
case XPATH_OP_NODE:
|
||||||
if (op->ch1 != -1)
|
if (op->ch1 != -1)
|
||||||
total += xmlXPathCompOpEval(ctxt, &comp->steps[op->ch1]);
|
total += xmlXPathCompOpEval(ctxt, &comp->steps[op->ch1]);
|
||||||
|
CHECK_ERROR0;
|
||||||
if (op->ch2 != -1)
|
if (op->ch2 != -1)
|
||||||
total += xmlXPathCompOpEval(ctxt, &comp->steps[op->ch2]);
|
total += xmlXPathCompOpEval(ctxt, &comp->steps[op->ch2]);
|
||||||
|
CHECK_ERROR0;
|
||||||
valuePush(ctxt, xmlXPathNewNodeSet(ctxt->context->node));
|
valuePush(ctxt, xmlXPathNewNodeSet(ctxt->context->node));
|
||||||
return (total);
|
return (total);
|
||||||
case XPATH_OP_RESET:
|
case XPATH_OP_RESET:
|
||||||
if (op->ch1 != -1)
|
if (op->ch1 != -1)
|
||||||
total += xmlXPathCompOpEval(ctxt, &comp->steps[op->ch1]);
|
total += xmlXPathCompOpEval(ctxt, &comp->steps[op->ch1]);
|
||||||
|
CHECK_ERROR0;
|
||||||
if (op->ch2 != -1)
|
if (op->ch2 != -1)
|
||||||
total += xmlXPathCompOpEval(ctxt, &comp->steps[op->ch2]);
|
total += xmlXPathCompOpEval(ctxt, &comp->steps[op->ch2]);
|
||||||
|
CHECK_ERROR0;
|
||||||
ctxt->context->node = NULL;
|
ctxt->context->node = NULL;
|
||||||
return (total);
|
return (total);
|
||||||
case XPATH_OP_COLLECT:{
|
case XPATH_OP_COLLECT:{
|
||||||
@ -9122,6 +9165,7 @@ xmlXPathCompOpEval(xmlXPathParserContextPtr ctxt, xmlXPathStepOpPtr op)
|
|||||||
return (total);
|
return (total);
|
||||||
|
|
||||||
total += xmlXPathCompOpEval(ctxt, &comp->steps[op->ch1]);
|
total += xmlXPathCompOpEval(ctxt, &comp->steps[op->ch1]);
|
||||||
|
CHECK_ERROR0;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Optimization for [n] selection where n is a number
|
* Optimization for [n] selection where n is a number
|
||||||
@ -9155,14 +9199,19 @@ xmlXPathCompOpEval(xmlXPathParserContextPtr ctxt, xmlXPathStepOpPtr op)
|
|||||||
xmlXPathObjectCopy((xmlXPathObjectPtr) op->value4));
|
xmlXPathObjectCopy((xmlXPathObjectPtr) op->value4));
|
||||||
return (total);
|
return (total);
|
||||||
case XPATH_OP_VARIABLE:{
|
case XPATH_OP_VARIABLE:{
|
||||||
|
xmlXPathObjectPtr val;
|
||||||
|
|
||||||
if (op->ch1 != -1)
|
if (op->ch1 != -1)
|
||||||
total +=
|
total +=
|
||||||
xmlXPathCompOpEval(ctxt, &comp->steps[op->ch1]);
|
xmlXPathCompOpEval(ctxt, &comp->steps[op->ch1]);
|
||||||
if (op->value5 == NULL)
|
if (op->value5 == NULL) {
|
||||||
valuePush(ctxt,
|
val = xmlXPathVariableLookup(ctxt->context, op->value4);
|
||||||
xmlXPathVariableLookup(ctxt->context,
|
if (val == NULL) {
|
||||||
op->value4));
|
ctxt->error = XPATH_UNDEF_VARIABLE_ERROR;
|
||||||
else {
|
return(0);
|
||||||
|
}
|
||||||
|
valuePush(ctxt, val);
|
||||||
|
} else {
|
||||||
const xmlChar *URI;
|
const xmlChar *URI;
|
||||||
|
|
||||||
URI = xmlXPathNsLookup(ctxt->context, op->value5);
|
URI = xmlXPathNsLookup(ctxt->context, op->value5);
|
||||||
@ -9172,19 +9221,37 @@ xmlXPathCompOpEval(xmlXPathParserContextPtr ctxt, xmlXPathStepOpPtr op)
|
|||||||
op->value4, op->value5);
|
op->value4, op->value5);
|
||||||
return (total);
|
return (total);
|
||||||
}
|
}
|
||||||
valuePush(ctxt,
|
val = xmlXPathVariableLookupNS(ctxt->context,
|
||||||
xmlXPathVariableLookupNS(ctxt->context,
|
op->value4, URI);
|
||||||
op->value4, URI));
|
if (val == NULL) {
|
||||||
|
ctxt->error = XPATH_UNDEF_VARIABLE_ERROR;
|
||||||
|
return(0);
|
||||||
|
}
|
||||||
|
valuePush(ctxt, val);
|
||||||
}
|
}
|
||||||
return (total);
|
return (total);
|
||||||
}
|
}
|
||||||
case XPATH_OP_FUNCTION:{
|
case XPATH_OP_FUNCTION:{
|
||||||
xmlXPathFunction func;
|
xmlXPathFunction func;
|
||||||
const xmlChar *oldFunc, *oldFuncURI;
|
const xmlChar *oldFunc, *oldFuncURI;
|
||||||
|
int i;
|
||||||
|
|
||||||
if (op->ch1 != -1)
|
if (op->ch1 != -1)
|
||||||
total +=
|
total +=
|
||||||
xmlXPathCompOpEval(ctxt, &comp->steps[op->ch1]);
|
xmlXPathCompOpEval(ctxt, &comp->steps[op->ch1]);
|
||||||
|
if (ctxt->valueNr < op->value) {
|
||||||
|
xmlGenericError(xmlGenericErrorContext,
|
||||||
|
"xmlXPathRunEval: parameter error\n");
|
||||||
|
ctxt->error = XPATH_INVALID_OPERAND;
|
||||||
|
return (total);
|
||||||
|
}
|
||||||
|
for (i = 0; i < op->value; i++)
|
||||||
|
if (ctxt->valueTab[(ctxt->valueNr - 1) - i] == NULL) {
|
||||||
|
xmlGenericError(xmlGenericErrorContext,
|
||||||
|
"xmlXPathRunEval: parameter error\n");
|
||||||
|
ctxt->error = XPATH_INVALID_OPERAND;
|
||||||
|
return (total);
|
||||||
|
}
|
||||||
if (op->cache != NULL)
|
if (op->cache != NULL)
|
||||||
func = (xmlXPathFunction) op->cache;
|
func = (xmlXPathFunction) op->cache;
|
||||||
else {
|
else {
|
||||||
@ -9227,8 +9294,10 @@ xmlXPathCompOpEval(xmlXPathParserContextPtr ctxt, xmlXPathStepOpPtr op)
|
|||||||
case XPATH_OP_ARG:
|
case XPATH_OP_ARG:
|
||||||
if (op->ch1 != -1)
|
if (op->ch1 != -1)
|
||||||
total += xmlXPathCompOpEval(ctxt, &comp->steps[op->ch1]);
|
total += xmlXPathCompOpEval(ctxt, &comp->steps[op->ch1]);
|
||||||
|
CHECK_ERROR0;
|
||||||
if (op->ch2 != -1)
|
if (op->ch2 != -1)
|
||||||
total += xmlXPathCompOpEval(ctxt, &comp->steps[op->ch2]);
|
total += xmlXPathCompOpEval(ctxt, &comp->steps[op->ch2]);
|
||||||
|
CHECK_ERROR0;
|
||||||
return (total);
|
return (total);
|
||||||
case XPATH_OP_PREDICATE:
|
case XPATH_OP_PREDICATE:
|
||||||
case XPATH_OP_FILTER:{
|
case XPATH_OP_FILTER:{
|
||||||
@ -9256,6 +9325,7 @@ xmlXPathCompOpEval(xmlXPathParserContextPtr ctxt, xmlXPathStepOpPtr op)
|
|||||||
xmlXPathCompOpEvalFirst(ctxt,
|
xmlXPathCompOpEvalFirst(ctxt,
|
||||||
&comp->steps[op->ch1],
|
&comp->steps[op->ch1],
|
||||||
&first);
|
&first);
|
||||||
|
CHECK_ERROR0;
|
||||||
/*
|
/*
|
||||||
* The nodeset should be in document order,
|
* The nodeset should be in document order,
|
||||||
* Keep only the first value
|
* Keep only the first value
|
||||||
@ -9289,6 +9359,7 @@ xmlXPathCompOpEval(xmlXPathParserContextPtr ctxt, xmlXPathStepOpPtr op)
|
|||||||
xmlXPathCompOpEvalLast(ctxt,
|
xmlXPathCompOpEvalLast(ctxt,
|
||||||
&comp->steps[op->ch1],
|
&comp->steps[op->ch1],
|
||||||
&last);
|
&last);
|
||||||
|
CHECK_ERROR0;
|
||||||
/*
|
/*
|
||||||
* The nodeset should be in document order,
|
* The nodeset should be in document order,
|
||||||
* Keep only the last value
|
* Keep only the last value
|
||||||
@ -9313,6 +9384,7 @@ xmlXPathCompOpEval(xmlXPathParserContextPtr ctxt, xmlXPathStepOpPtr op)
|
|||||||
if (op->ch1 != -1)
|
if (op->ch1 != -1)
|
||||||
total +=
|
total +=
|
||||||
xmlXPathCompOpEval(ctxt, &comp->steps[op->ch1]);
|
xmlXPathCompOpEval(ctxt, &comp->steps[op->ch1]);
|
||||||
|
CHECK_ERROR0;
|
||||||
if (op->ch2 == -1)
|
if (op->ch2 == -1)
|
||||||
return (total);
|
return (total);
|
||||||
if (ctxt->value == NULL)
|
if (ctxt->value == NULL)
|
||||||
@ -9427,6 +9499,7 @@ xmlXPathCompOpEval(xmlXPathParserContextPtr ctxt, xmlXPathStepOpPtr op)
|
|||||||
total +=
|
total +=
|
||||||
xmlXPathCompOpEval(ctxt,
|
xmlXPathCompOpEval(ctxt,
|
||||||
&comp->steps[op->ch2]);
|
&comp->steps[op->ch2]);
|
||||||
|
CHECK_ERROR0;
|
||||||
res = valuePop(ctxt);
|
res = valuePop(ctxt);
|
||||||
if (res != NULL)
|
if (res != NULL)
|
||||||
xmlXPathFreeObject(res);
|
xmlXPathFreeObject(res);
|
||||||
@ -9493,6 +9566,7 @@ xmlXPathCompOpEval(xmlXPathParserContextPtr ctxt, xmlXPathStepOpPtr op)
|
|||||||
case XPATH_OP_SORT:
|
case XPATH_OP_SORT:
|
||||||
if (op->ch1 != -1)
|
if (op->ch1 != -1)
|
||||||
total += xmlXPathCompOpEval(ctxt, &comp->steps[op->ch1]);
|
total += xmlXPathCompOpEval(ctxt, &comp->steps[op->ch1]);
|
||||||
|
CHECK_ERROR0;
|
||||||
if ((ctxt->value != NULL) &&
|
if ((ctxt->value != NULL) &&
|
||||||
(ctxt->value->type == XPATH_NODESET) &&
|
(ctxt->value->type == XPATH_NODESET) &&
|
||||||
(ctxt->value->nodesetval != NULL))
|
(ctxt->value->nodesetval != NULL))
|
||||||
|
Reference in New Issue
Block a user