mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2025-01-11 15:27:47 +00:00
Fix some XPath relative node resets
* src/util/xml.c: The virXPath... function take extra care to preserve the XPath context node (ctxt->node) but in the case of virXPathString and virXPathBoolean they forgot to do this on the error path. This patch fixes this and move all ctxt->node = relnode instuctions just after the xmlXPathEval() to make sure this doesn't happen if this code is modified.
This commit is contained in:
parent
25e2857c21
commit
237f3bf8da
@ -62,6 +62,7 @@ virXPathString(virConnectPtr conn,
|
|||||||
}
|
}
|
||||||
relnode = ctxt->node;
|
relnode = ctxt->node;
|
||||||
obj = xmlXPathEval(BAD_CAST xpath, ctxt);
|
obj = xmlXPathEval(BAD_CAST xpath, ctxt);
|
||||||
|
ctxt->node = relnode;
|
||||||
if ((obj == NULL) || (obj->type != XPATH_STRING) ||
|
if ((obj == NULL) || (obj->type != XPATH_STRING) ||
|
||||||
(obj->stringval == NULL) || (obj->stringval[0] == 0)) {
|
(obj->stringval == NULL) || (obj->stringval[0] == 0)) {
|
||||||
xmlXPathFreeObject(obj);
|
xmlXPathFreeObject(obj);
|
||||||
@ -72,7 +73,6 @@ virXPathString(virConnectPtr conn,
|
|||||||
if (ret == NULL) {
|
if (ret == NULL) {
|
||||||
virReportOOMError(conn);
|
virReportOOMError(conn);
|
||||||
}
|
}
|
||||||
ctxt->node = relnode;
|
|
||||||
return (ret);
|
return (ret);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -133,16 +133,15 @@ virXPathNumber(virConnectPtr conn,
|
|||||||
}
|
}
|
||||||
relnode = ctxt->node;
|
relnode = ctxt->node;
|
||||||
obj = xmlXPathEval(BAD_CAST xpath, ctxt);
|
obj = xmlXPathEval(BAD_CAST xpath, ctxt);
|
||||||
|
ctxt->node = relnode;
|
||||||
if ((obj == NULL) || (obj->type != XPATH_NUMBER) ||
|
if ((obj == NULL) || (obj->type != XPATH_NUMBER) ||
|
||||||
(isnan(obj->floatval))) {
|
(isnan(obj->floatval))) {
|
||||||
xmlXPathFreeObject(obj);
|
xmlXPathFreeObject(obj);
|
||||||
ctxt->node = relnode;
|
|
||||||
return (-1);
|
return (-1);
|
||||||
}
|
}
|
||||||
|
|
||||||
*value = obj->floatval;
|
*value = obj->floatval;
|
||||||
xmlXPathFreeObject(obj);
|
xmlXPathFreeObject(obj);
|
||||||
ctxt->node = relnode;
|
|
||||||
return (0);
|
return (0);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -164,6 +163,7 @@ virXPathLongBase(virConnectPtr conn,
|
|||||||
}
|
}
|
||||||
relnode = ctxt->node;
|
relnode = ctxt->node;
|
||||||
obj = xmlXPathEval(BAD_CAST xpath, ctxt);
|
obj = xmlXPathEval(BAD_CAST xpath, ctxt);
|
||||||
|
ctxt->node = relnode;
|
||||||
if ((obj != NULL) && (obj->type == XPATH_STRING) &&
|
if ((obj != NULL) && (obj->type == XPATH_STRING) &&
|
||||||
(obj->stringval != NULL) && (obj->stringval[0] != 0)) {
|
(obj->stringval != NULL) && (obj->stringval[0] != 0)) {
|
||||||
char *conv = NULL;
|
char *conv = NULL;
|
||||||
@ -186,7 +186,6 @@ virXPathLongBase(virConnectPtr conn,
|
|||||||
}
|
}
|
||||||
|
|
||||||
xmlXPathFreeObject(obj);
|
xmlXPathFreeObject(obj);
|
||||||
ctxt->node = relnode;
|
|
||||||
return (ret);
|
return (ret);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -251,6 +250,7 @@ virXPathULongBase(virConnectPtr conn,
|
|||||||
}
|
}
|
||||||
relnode = ctxt->node;
|
relnode = ctxt->node;
|
||||||
obj = xmlXPathEval(BAD_CAST xpath, ctxt);
|
obj = xmlXPathEval(BAD_CAST xpath, ctxt);
|
||||||
|
ctxt->node = relnode;
|
||||||
if ((obj != NULL) && (obj->type == XPATH_STRING) &&
|
if ((obj != NULL) && (obj->type == XPATH_STRING) &&
|
||||||
(obj->stringval != NULL) && (obj->stringval[0] != 0)) {
|
(obj->stringval != NULL) && (obj->stringval[0] != 0)) {
|
||||||
char *conv = NULL;
|
char *conv = NULL;
|
||||||
@ -273,7 +273,6 @@ virXPathULongBase(virConnectPtr conn,
|
|||||||
}
|
}
|
||||||
|
|
||||||
xmlXPathFreeObject(obj);
|
xmlXPathFreeObject(obj);
|
||||||
ctxt->node = relnode;
|
|
||||||
return (ret);
|
return (ret);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -349,6 +348,7 @@ virXPathULongLong(virConnectPtr conn,
|
|||||||
}
|
}
|
||||||
relnode = ctxt->node;
|
relnode = ctxt->node;
|
||||||
obj = xmlXPathEval(BAD_CAST xpath, ctxt);
|
obj = xmlXPathEval(BAD_CAST xpath, ctxt);
|
||||||
|
ctxt->node = relnode;
|
||||||
if ((obj != NULL) && (obj->type == XPATH_STRING) &&
|
if ((obj != NULL) && (obj->type == XPATH_STRING) &&
|
||||||
(obj->stringval != NULL) && (obj->stringval[0] != 0)) {
|
(obj->stringval != NULL) && (obj->stringval[0] != 0)) {
|
||||||
char *conv = NULL;
|
char *conv = NULL;
|
||||||
@ -371,7 +371,6 @@ virXPathULongLong(virConnectPtr conn,
|
|||||||
}
|
}
|
||||||
|
|
||||||
xmlXPathFreeObject(obj);
|
xmlXPathFreeObject(obj);
|
||||||
ctxt->node = relnode;
|
|
||||||
return (ret);
|
return (ret);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -407,6 +406,7 @@ virXPathBoolean(virConnectPtr conn,
|
|||||||
}
|
}
|
||||||
relnode = ctxt->node;
|
relnode = ctxt->node;
|
||||||
obj = xmlXPathEval(BAD_CAST xpath, ctxt);
|
obj = xmlXPathEval(BAD_CAST xpath, ctxt);
|
||||||
|
ctxt->node = relnode;
|
||||||
if ((obj == NULL) || (obj->type != XPATH_BOOLEAN) ||
|
if ((obj == NULL) || (obj->type != XPATH_BOOLEAN) ||
|
||||||
(obj->boolval < 0) || (obj->boolval > 1)) {
|
(obj->boolval < 0) || (obj->boolval > 1)) {
|
||||||
xmlXPathFreeObject(obj);
|
xmlXPathFreeObject(obj);
|
||||||
@ -415,7 +415,6 @@ virXPathBoolean(virConnectPtr conn,
|
|||||||
ret = obj->boolval;
|
ret = obj->boolval;
|
||||||
|
|
||||||
xmlXPathFreeObject(obj);
|
xmlXPathFreeObject(obj);
|
||||||
ctxt->node = relnode;
|
|
||||||
return (ret);
|
return (ret);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -445,17 +444,16 @@ virXPathNode(virConnectPtr conn,
|
|||||||
}
|
}
|
||||||
relnode = ctxt->node;
|
relnode = ctxt->node;
|
||||||
obj = xmlXPathEval(BAD_CAST xpath, ctxt);
|
obj = xmlXPathEval(BAD_CAST xpath, ctxt);
|
||||||
|
ctxt->node = relnode;
|
||||||
if ((obj == NULL) || (obj->type != XPATH_NODESET) ||
|
if ((obj == NULL) || (obj->type != XPATH_NODESET) ||
|
||||||
(obj->nodesetval == NULL) || (obj->nodesetval->nodeNr <= 0) ||
|
(obj->nodesetval == NULL) || (obj->nodesetval->nodeNr <= 0) ||
|
||||||
(obj->nodesetval->nodeTab == NULL)) {
|
(obj->nodesetval->nodeTab == NULL)) {
|
||||||
xmlXPathFreeObject(obj);
|
xmlXPathFreeObject(obj);
|
||||||
ctxt->node = relnode;
|
|
||||||
return (NULL);
|
return (NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
ret = obj->nodesetval->nodeTab[0];
|
ret = obj->nodesetval->nodeTab[0];
|
||||||
xmlXPathFreeObject(obj);
|
xmlXPathFreeObject(obj);
|
||||||
ctxt->node = relnode;
|
|
||||||
return (ret);
|
return (ret);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -491,10 +489,10 @@ virXPathNodeSet(virConnectPtr conn,
|
|||||||
|
|
||||||
relnode = ctxt->node;
|
relnode = ctxt->node;
|
||||||
obj = xmlXPathEval(BAD_CAST xpath, ctxt);
|
obj = xmlXPathEval(BAD_CAST xpath, ctxt);
|
||||||
|
ctxt->node = relnode;
|
||||||
if ((obj == NULL) || (obj->type != XPATH_NODESET) ||
|
if ((obj == NULL) || (obj->type != XPATH_NODESET) ||
|
||||||
(obj->nodesetval == NULL) || (obj->nodesetval->nodeNr < 0)) {
|
(obj->nodesetval == NULL) || (obj->nodesetval->nodeNr < 0)) {
|
||||||
xmlXPathFreeObject(obj);
|
xmlXPathFreeObject(obj);
|
||||||
ctxt->node = relnode;
|
|
||||||
return (-1);
|
return (-1);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -509,6 +507,5 @@ virXPathNodeSet(virConnectPtr conn,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
xmlXPathFreeObject(obj);
|
xmlXPathFreeObject(obj);
|
||||||
ctxt->node = relnode;
|
|
||||||
return (ret);
|
return (ret);
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user