提交 183f9631 编写于 作者: P Peter Krempa

util: storage: Sanitize parsing of disk auth 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>
上级 74942ff0
......@@ -7218,7 +7218,8 @@ virDomainHostdevSubsysSCSIHostDefParseXML(xmlNodePtr sourcenode,
static int
virDomainHostdevSubsysSCSIiSCSIDefParseXML(xmlNodePtr sourcenode,
virDomainHostdevSubsysSCSIPtr def)
virDomainHostdevSubsysSCSIPtr def,
xmlXPathContextPtr ctxt)
{
int ret = -1;
int auth_secret_usage = -1;
......@@ -7259,7 +7260,7 @@ virDomainHostdevSubsysSCSIiSCSIDefParseXML(xmlNodePtr sourcenode,
while (cur != NULL) {
if (cur->type == XML_ELEMENT_NODE &&
virXMLNodeNameEqual(cur, "auth")) {
if (!(authdef = virStorageAuthDefParse(sourcenode->doc, cur)))
if (!(authdef = virStorageAuthDefParse(cur, ctxt)))
goto cleanup;
if ((auth_secret_usage =
virSecretUsageTypeFromString(authdef->secrettype)) < 0) {
......@@ -7288,7 +7289,8 @@ virDomainHostdevSubsysSCSIiSCSIDefParseXML(xmlNodePtr sourcenode,
static int
virDomainHostdevSubsysSCSIDefParseXML(xmlNodePtr sourcenode,
virDomainHostdevSubsysSCSIPtr scsisrc)
virDomainHostdevSubsysSCSIPtr scsisrc,
xmlXPathContextPtr ctxt)
{
char *protocol = NULL;
int ret = -1;
......@@ -7305,7 +7307,7 @@ virDomainHostdevSubsysSCSIDefParseXML(xmlNodePtr sourcenode,
}
if (scsisrc->protocol == VIR_DOMAIN_HOSTDEV_SCSI_PROTOCOL_TYPE_ISCSI)
ret = virDomainHostdevSubsysSCSIiSCSIDefParseXML(sourcenode, scsisrc);
ret = virDomainHostdevSubsysSCSIiSCSIDefParseXML(sourcenode, scsisrc, ctxt);
else
ret = virDomainHostdevSubsysSCSIHostDefParseXML(sourcenode, scsisrc);
......@@ -7550,7 +7552,7 @@ virDomainHostdevDefParseXMLSubsys(xmlNodePtr node,
break;
case VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_SCSI:
if (virDomainHostdevSubsysSCSIDefParseXML(sourcenode, scsisrc) < 0)
if (virDomainHostdevSubsysSCSIDefParseXML(sourcenode, scsisrc, ctxt) < 0)
goto error;
break;
......@@ -8540,7 +8542,8 @@ virDomainDiskSourceNetworkParse(xmlNodePtr node,
static int
virDomainDiskSourceAuthParse(xmlNodePtr node,
virStorageAuthDefPtr *authdefsrc)
virStorageAuthDefPtr *authdefsrc,
xmlXPathContextPtr ctxt)
{
xmlNodePtr child;
virStorageAuthDefPtr authdef;
......@@ -8549,7 +8552,7 @@ virDomainDiskSourceAuthParse(xmlNodePtr node,
if (child->type == XML_ELEMENT_NODE &&
virXMLNodeNameEqual(child, "auth")) {
if (!(authdef = virStorageAuthDefParse(node->doc, child)))
if (!(authdef = virStorageAuthDefParse(child, ctxt)))
return -1;
*authdefsrc = authdef;
......@@ -8653,7 +8656,7 @@ virDomainDiskSourceParse(xmlNodePtr node,
goto cleanup;
}
if (virDomainDiskSourceAuthParse(node, &src->auth) < 0)
if (virDomainDiskSourceAuthParse(node, &src->auth, ctxt) < 0)
goto cleanup;
if (virDomainDiskSourceEncryptionParse(node, &src->encryption) < 0)
......@@ -9401,7 +9404,7 @@ virDomainDiskDefParseXML(virDomainXMLOptionPtr xmlopt,
goto error;
}
if (!(authdef = virStorageAuthDefParse(node->doc, cur)))
if (!(authdef = virStorageAuthDefParse(cur, ctxt)))
goto error;
} else if (virXMLNodeNameEqual(cur, "iotune")) {
if (virDomainDiskDefIotuneParse(def, ctxt) < 0)
......
......@@ -527,7 +527,7 @@ virStoragePoolDefParseSource(xmlXPathContextPtr ctxt,
}
if ((authnode = virXPathNode("./auth", ctxt))) {
if (!(authdef = virStorageAuthDefParse(node->doc, authnode)))
if (!(authdef = virStorageAuthDefParse(authnode, ctxt)))
goto cleanup;
if (authdef->authType == VIR_STORAGE_AUTH_TYPE_NONE) {
......
......@@ -1809,16 +1809,20 @@ virStorageAuthDefCopy(const virStorageAuthDef *src)
}
static virStorageAuthDefPtr
virStorageAuthDefParseXML(xmlXPathContextPtr ctxt)
virStorageAuthDefPtr
virStorageAuthDefParse(xmlNodePtr node,
xmlXPathContextPtr ctxt)
{
xmlNodePtr saveNode = ctxt->node;
virStorageAuthDefPtr authdef = NULL;
virStorageAuthDefPtr ret = NULL;
xmlNodePtr secretnode = NULL;
char *authtype = NULL;
ctxt->node = node;
if (VIR_ALLOC(authdef) < 0)
return NULL;
goto cleanup;
if (!(authdef->username = virXPathString("string(./@username)", ctxt))) {
virReportError(VIR_ERR_XML_ERROR, "%s",
......@@ -1862,32 +1866,12 @@ virStorageAuthDefParseXML(xmlXPathContextPtr ctxt)
cleanup:
VIR_FREE(authtype);
virStorageAuthDefFree(authdef);
ctxt->node = saveNode;
return ret;
}
virStorageAuthDefPtr
virStorageAuthDefParse(xmlDocPtr xml, xmlNodePtr root)
{
xmlXPathContextPtr ctxt = NULL;
virStorageAuthDefPtr authdef = NULL;
ctxt = xmlXPathNewContext(xml);
if (ctxt == NULL) {
virReportOOMError();
goto cleanup;
}
ctxt->node = root;
authdef = virStorageAuthDefParseXML(ctxt);
cleanup:
xmlXPathFreeContext(ctxt);
return authdef;
}
void
virStorageAuthDefFormat(virBufferPtr buf,
virStorageAuthDefPtr authdef)
......
......@@ -366,7 +366,8 @@ int virStorageFileGetSCSIKey(const char *path,
void virStorageAuthDefFree(virStorageAuthDefPtr def);
virStorageAuthDefPtr virStorageAuthDefCopy(const virStorageAuthDef *src);
virStorageAuthDefPtr virStorageAuthDefParse(xmlDocPtr xml, xmlNodePtr root);
virStorageAuthDefPtr virStorageAuthDefParse(xmlNodePtr node,
xmlXPathContextPtr ctxt);
void virStorageAuthDefFormat(virBufferPtr buf, virStorageAuthDefPtr authdef);
virSecurityDeviceLabelDefPtr
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册