mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2025-01-23 13:05:27 +00:00
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: Peter Krempa <pkrempa@redhat.com>
This commit is contained in:
parent
74942ff0b6
commit
183f96314d
@ -7218,7 +7218,8 @@ virDomainHostdevSubsysSCSIHostDefParseXML(xmlNodePtr sourcenode,
|
|||||||
|
|
||||||
static int
|
static int
|
||||||
virDomainHostdevSubsysSCSIiSCSIDefParseXML(xmlNodePtr sourcenode,
|
virDomainHostdevSubsysSCSIiSCSIDefParseXML(xmlNodePtr sourcenode,
|
||||||
virDomainHostdevSubsysSCSIPtr def)
|
virDomainHostdevSubsysSCSIPtr def,
|
||||||
|
xmlXPathContextPtr ctxt)
|
||||||
{
|
{
|
||||||
int ret = -1;
|
int ret = -1;
|
||||||
int auth_secret_usage = -1;
|
int auth_secret_usage = -1;
|
||||||
@ -7259,7 +7260,7 @@ virDomainHostdevSubsysSCSIiSCSIDefParseXML(xmlNodePtr sourcenode,
|
|||||||
while (cur != NULL) {
|
while (cur != NULL) {
|
||||||
if (cur->type == XML_ELEMENT_NODE &&
|
if (cur->type == XML_ELEMENT_NODE &&
|
||||||
virXMLNodeNameEqual(cur, "auth")) {
|
virXMLNodeNameEqual(cur, "auth")) {
|
||||||
if (!(authdef = virStorageAuthDefParse(sourcenode->doc, cur)))
|
if (!(authdef = virStorageAuthDefParse(cur, ctxt)))
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
if ((auth_secret_usage =
|
if ((auth_secret_usage =
|
||||||
virSecretUsageTypeFromString(authdef->secrettype)) < 0) {
|
virSecretUsageTypeFromString(authdef->secrettype)) < 0) {
|
||||||
@ -7288,7 +7289,8 @@ virDomainHostdevSubsysSCSIiSCSIDefParseXML(xmlNodePtr sourcenode,
|
|||||||
|
|
||||||
static int
|
static int
|
||||||
virDomainHostdevSubsysSCSIDefParseXML(xmlNodePtr sourcenode,
|
virDomainHostdevSubsysSCSIDefParseXML(xmlNodePtr sourcenode,
|
||||||
virDomainHostdevSubsysSCSIPtr scsisrc)
|
virDomainHostdevSubsysSCSIPtr scsisrc,
|
||||||
|
xmlXPathContextPtr ctxt)
|
||||||
{
|
{
|
||||||
char *protocol = NULL;
|
char *protocol = NULL;
|
||||||
int ret = -1;
|
int ret = -1;
|
||||||
@ -7305,7 +7307,7 @@ virDomainHostdevSubsysSCSIDefParseXML(xmlNodePtr sourcenode,
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (scsisrc->protocol == VIR_DOMAIN_HOSTDEV_SCSI_PROTOCOL_TYPE_ISCSI)
|
if (scsisrc->protocol == VIR_DOMAIN_HOSTDEV_SCSI_PROTOCOL_TYPE_ISCSI)
|
||||||
ret = virDomainHostdevSubsysSCSIiSCSIDefParseXML(sourcenode, scsisrc);
|
ret = virDomainHostdevSubsysSCSIiSCSIDefParseXML(sourcenode, scsisrc, ctxt);
|
||||||
else
|
else
|
||||||
ret = virDomainHostdevSubsysSCSIHostDefParseXML(sourcenode, scsisrc);
|
ret = virDomainHostdevSubsysSCSIHostDefParseXML(sourcenode, scsisrc);
|
||||||
|
|
||||||
@ -7550,7 +7552,7 @@ virDomainHostdevDefParseXMLSubsys(xmlNodePtr node,
|
|||||||
break;
|
break;
|
||||||
|
|
||||||
case VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_SCSI:
|
case VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_SCSI:
|
||||||
if (virDomainHostdevSubsysSCSIDefParseXML(sourcenode, scsisrc) < 0)
|
if (virDomainHostdevSubsysSCSIDefParseXML(sourcenode, scsisrc, ctxt) < 0)
|
||||||
goto error;
|
goto error;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
@ -8540,7 +8542,8 @@ virDomainDiskSourceNetworkParse(xmlNodePtr node,
|
|||||||
|
|
||||||
static int
|
static int
|
||||||
virDomainDiskSourceAuthParse(xmlNodePtr node,
|
virDomainDiskSourceAuthParse(xmlNodePtr node,
|
||||||
virStorageAuthDefPtr *authdefsrc)
|
virStorageAuthDefPtr *authdefsrc,
|
||||||
|
xmlXPathContextPtr ctxt)
|
||||||
{
|
{
|
||||||
xmlNodePtr child;
|
xmlNodePtr child;
|
||||||
virStorageAuthDefPtr authdef;
|
virStorageAuthDefPtr authdef;
|
||||||
@ -8549,7 +8552,7 @@ virDomainDiskSourceAuthParse(xmlNodePtr node,
|
|||||||
if (child->type == XML_ELEMENT_NODE &&
|
if (child->type == XML_ELEMENT_NODE &&
|
||||||
virXMLNodeNameEqual(child, "auth")) {
|
virXMLNodeNameEqual(child, "auth")) {
|
||||||
|
|
||||||
if (!(authdef = virStorageAuthDefParse(node->doc, child)))
|
if (!(authdef = virStorageAuthDefParse(child, ctxt)))
|
||||||
return -1;
|
return -1;
|
||||||
|
|
||||||
*authdefsrc = authdef;
|
*authdefsrc = authdef;
|
||||||
@ -8653,7 +8656,7 @@ virDomainDiskSourceParse(xmlNodePtr node,
|
|||||||
goto cleanup;
|
goto cleanup;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (virDomainDiskSourceAuthParse(node, &src->auth) < 0)
|
if (virDomainDiskSourceAuthParse(node, &src->auth, ctxt) < 0)
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
|
|
||||||
if (virDomainDiskSourceEncryptionParse(node, &src->encryption) < 0)
|
if (virDomainDiskSourceEncryptionParse(node, &src->encryption) < 0)
|
||||||
@ -9401,7 +9404,7 @@ virDomainDiskDefParseXML(virDomainXMLOptionPtr xmlopt,
|
|||||||
goto error;
|
goto error;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!(authdef = virStorageAuthDefParse(node->doc, cur)))
|
if (!(authdef = virStorageAuthDefParse(cur, ctxt)))
|
||||||
goto error;
|
goto error;
|
||||||
} else if (virXMLNodeNameEqual(cur, "iotune")) {
|
} else if (virXMLNodeNameEqual(cur, "iotune")) {
|
||||||
if (virDomainDiskDefIotuneParse(def, ctxt) < 0)
|
if (virDomainDiskDefIotuneParse(def, ctxt) < 0)
|
||||||
|
@ -527,7 +527,7 @@ virStoragePoolDefParseSource(xmlXPathContextPtr ctxt,
|
|||||||
}
|
}
|
||||||
|
|
||||||
if ((authnode = virXPathNode("./auth", ctxt))) {
|
if ((authnode = virXPathNode("./auth", ctxt))) {
|
||||||
if (!(authdef = virStorageAuthDefParse(node->doc, authnode)))
|
if (!(authdef = virStorageAuthDefParse(authnode, ctxt)))
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
|
|
||||||
if (authdef->authType == VIR_STORAGE_AUTH_TYPE_NONE) {
|
if (authdef->authType == VIR_STORAGE_AUTH_TYPE_NONE) {
|
||||||
|
@ -1809,16 +1809,20 @@ virStorageAuthDefCopy(const virStorageAuthDef *src)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
static virStorageAuthDefPtr
|
virStorageAuthDefPtr
|
||||||
virStorageAuthDefParseXML(xmlXPathContextPtr ctxt)
|
virStorageAuthDefParse(xmlNodePtr node,
|
||||||
|
xmlXPathContextPtr ctxt)
|
||||||
{
|
{
|
||||||
|
xmlNodePtr saveNode = ctxt->node;
|
||||||
virStorageAuthDefPtr authdef = NULL;
|
virStorageAuthDefPtr authdef = NULL;
|
||||||
virStorageAuthDefPtr ret = NULL;
|
virStorageAuthDefPtr ret = NULL;
|
||||||
xmlNodePtr secretnode = NULL;
|
xmlNodePtr secretnode = NULL;
|
||||||
char *authtype = NULL;
|
char *authtype = NULL;
|
||||||
|
|
||||||
|
ctxt->node = node;
|
||||||
|
|
||||||
if (VIR_ALLOC(authdef) < 0)
|
if (VIR_ALLOC(authdef) < 0)
|
||||||
return NULL;
|
goto cleanup;
|
||||||
|
|
||||||
if (!(authdef->username = virXPathString("string(./@username)", ctxt))) {
|
if (!(authdef->username = virXPathString("string(./@username)", ctxt))) {
|
||||||
virReportError(VIR_ERR_XML_ERROR, "%s",
|
virReportError(VIR_ERR_XML_ERROR, "%s",
|
||||||
@ -1862,32 +1866,12 @@ virStorageAuthDefParseXML(xmlXPathContextPtr ctxt)
|
|||||||
cleanup:
|
cleanup:
|
||||||
VIR_FREE(authtype);
|
VIR_FREE(authtype);
|
||||||
virStorageAuthDefFree(authdef);
|
virStorageAuthDefFree(authdef);
|
||||||
|
ctxt->node = saveNode;
|
||||||
|
|
||||||
return ret;
|
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
|
void
|
||||||
virStorageAuthDefFormat(virBufferPtr buf,
|
virStorageAuthDefFormat(virBufferPtr buf,
|
||||||
virStorageAuthDefPtr authdef)
|
virStorageAuthDefPtr authdef)
|
||||||
|
@ -366,7 +366,8 @@ int virStorageFileGetSCSIKey(const char *path,
|
|||||||
|
|
||||||
void virStorageAuthDefFree(virStorageAuthDefPtr def);
|
void virStorageAuthDefFree(virStorageAuthDefPtr def);
|
||||||
virStorageAuthDefPtr virStorageAuthDefCopy(const virStorageAuthDef *src);
|
virStorageAuthDefPtr virStorageAuthDefCopy(const virStorageAuthDef *src);
|
||||||
virStorageAuthDefPtr virStorageAuthDefParse(xmlDocPtr xml, xmlNodePtr root);
|
virStorageAuthDefPtr virStorageAuthDefParse(xmlNodePtr node,
|
||||||
|
xmlXPathContextPtr ctxt);
|
||||||
void virStorageAuthDefFormat(virBufferPtr buf, virStorageAuthDefPtr authdef);
|
void virStorageAuthDefFormat(virBufferPtr buf, virStorageAuthDefPtr authdef);
|
||||||
|
|
||||||
virSecurityDeviceLabelDefPtr
|
virSecurityDeviceLabelDefPtr
|
||||||
|
Loading…
x
Reference in New Issue
Block a user