mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2025-01-22 12:35:17 +00:00
util: storage: Sanitize parsing of disk encryption XMLs
Pass in the XPath context as we do in all other places rather than allocating a new one. Signed-off-by: Peter Krempa <pkrempa@redhat.com>
This commit is contained in:
parent
15948e6266
commit
1e6e34b144
@ -8542,7 +8542,8 @@ virDomainDiskSourceNetworkParse(xmlNodePtr node,
|
||||
|
||||
static int
|
||||
virDomainDiskSourceEncryptionParse(xmlNodePtr node,
|
||||
virStorageEncryptionPtr *encryptionsrc)
|
||||
virStorageEncryptionPtr *encryptionsrc,
|
||||
xmlXPathContextPtr ctxt)
|
||||
{
|
||||
xmlNodePtr child;
|
||||
virStorageEncryptionPtr encryption = NULL;
|
||||
@ -8551,7 +8552,7 @@ virDomainDiskSourceEncryptionParse(xmlNodePtr node,
|
||||
if (child->type == XML_ELEMENT_NODE &&
|
||||
virXMLNodeNameEqual(child, "encryption")) {
|
||||
|
||||
if (!(encryption = virStorageEncryptionParseNode(node->doc, child)))
|
||||
if (!(encryption = virStorageEncryptionParseNode(child, ctxt)))
|
||||
return -1;
|
||||
|
||||
*encryptionsrc = encryption;
|
||||
@ -8637,7 +8638,7 @@ virDomainDiskSourceParse(xmlNodePtr node,
|
||||
!(src->auth = virStorageAuthDefParse(tmp, ctxt)))
|
||||
goto cleanup;
|
||||
|
||||
if (virDomainDiskSourceEncryptionParse(node, &src->encryption) < 0)
|
||||
if (virDomainDiskSourceEncryptionParse(node, &src->encryption, ctxt) < 0)
|
||||
goto cleanup;
|
||||
|
||||
if (virDomainDiskSourcePrivateDataParse(ctxt, src, flags, xmlopt) < 0)
|
||||
@ -9408,7 +9409,7 @@ virDomainDiskDefParseXML(virDomainXMLOptionPtr xmlopt,
|
||||
goto error;
|
||||
}
|
||||
|
||||
if (!(encryption = virStorageEncryptionParseNode(node->doc, cur)))
|
||||
if (!(encryption = virStorageEncryptionParseNode(cur, ctxt)))
|
||||
goto error;
|
||||
} else if (!serial &&
|
||||
virXMLNodeNameEqual(cur, "serial")) {
|
||||
|
@ -1209,8 +1209,7 @@ virStorageVolDefParseXML(virStoragePoolDefPtr pool,
|
||||
|
||||
node = virXPathNode("./target/encryption", ctxt);
|
||||
if (node != NULL) {
|
||||
ret->target.encryption = virStorageEncryptionParseNode(ctxt->doc,
|
||||
node);
|
||||
ret->target.encryption = virStorageEncryptionParseNode(node, ctxt);
|
||||
if (ret->target.encryption == NULL)
|
||||
goto error;
|
||||
}
|
||||
|
@ -242,9 +242,11 @@ virStorageEncryptionInfoParseIvgen(xmlNodePtr info_node,
|
||||
}
|
||||
|
||||
|
||||
static virStorageEncryptionPtr
|
||||
virStorageEncryptionParseXML(xmlXPathContextPtr ctxt)
|
||||
virStorageEncryptionPtr
|
||||
virStorageEncryptionParseNode(xmlNodePtr node,
|
||||
xmlXPathContextPtr ctxt)
|
||||
{
|
||||
xmlNodePtr saveNode = ctxt->node;
|
||||
xmlNodePtr *nodes = NULL;
|
||||
virStorageEncryptionPtr encdef = NULL;
|
||||
virStorageEncryptionPtr ret = NULL;
|
||||
@ -252,6 +254,8 @@ virStorageEncryptionParseXML(xmlXPathContextPtr ctxt)
|
||||
int n;
|
||||
size_t i;
|
||||
|
||||
ctxt->node = node;
|
||||
|
||||
if (VIR_ALLOC(encdef) < 0)
|
||||
goto cleanup;
|
||||
|
||||
@ -311,36 +315,11 @@ virStorageEncryptionParseXML(xmlXPathContextPtr ctxt)
|
||||
VIR_FREE(format_str);
|
||||
VIR_FREE(nodes);
|
||||
virStorageEncryptionFree(encdef);
|
||||
ctxt->node = saveNode;
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
virStorageEncryptionPtr
|
||||
virStorageEncryptionParseNode(xmlDocPtr xml, xmlNodePtr root)
|
||||
{
|
||||
xmlXPathContextPtr ctxt = NULL;
|
||||
virStorageEncryptionPtr enc = NULL;
|
||||
|
||||
if (STRNEQ((const char *) root->name, "encryption")) {
|
||||
virReportError(VIR_ERR_XML_ERROR,
|
||||
"%s", _("unknown root element for volume "
|
||||
"encryption information"));
|
||||
goto cleanup;
|
||||
}
|
||||
|
||||
ctxt = xmlXPathNewContext(xml);
|
||||
if (ctxt == NULL) {
|
||||
virReportOOMError();
|
||||
goto cleanup;
|
||||
}
|
||||
|
||||
ctxt->node = root;
|
||||
enc = virStorageEncryptionParseXML(ctxt);
|
||||
|
||||
cleanup:
|
||||
xmlXPathFreeContext(ctxt);
|
||||
return enc;
|
||||
}
|
||||
|
||||
|
||||
static int
|
||||
virStorageEncryptionSecretFormat(virBufferPtr buf,
|
||||
|
@ -83,8 +83,8 @@ virStorageEncryptionPtr virStorageEncryptionCopy(const virStorageEncryption *src
|
||||
|
||||
void virStorageEncryptionFree(virStorageEncryptionPtr enc);
|
||||
|
||||
virStorageEncryptionPtr virStorageEncryptionParseNode(xmlDocPtr xml,
|
||||
xmlNodePtr root);
|
||||
virStorageEncryptionPtr virStorageEncryptionParseNode(xmlNodePtr node,
|
||||
xmlXPathContextPtr ctxt);
|
||||
int virStorageEncryptionFormat(virBufferPtr buf,
|
||||
virStorageEncryptionPtr enc);
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user