提交 1e6e34b1 编写于 作者: P Peter Krempa

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: NPeter Krempa <pkrempa@redhat.com>
上级 15948e62
......@@ -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,34 +315,9 @@ virStorageEncryptionParseXML(xmlXPathContextPtr ctxt)
VIR_FREE(format_str);
VIR_FREE(nodes);
virStorageEncryptionFree(encdef);
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->node = saveNode;
ctxt = xmlXPathNewContext(xml);
if (ctxt == NULL) {
virReportOOMError();
goto cleanup;
}
ctxt->node = root;
enc = virStorageEncryptionParseXML(ctxt);
cleanup:
xmlXPathFreeContext(ctxt);
return enc;
return ret;
}
......
......@@ -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);
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册