From: Martin Kletzander <mkletzan@redhat.com>
This function performs only parsing with the underlying
virDomainDefParseIDs() function to get needed metadata for any ACL
checks, but nothing else to avoid extraneous allocations and any
parser-induced DoS over ACL-forbidden connections.
Signed-off-by: Martin Kletzander <mkletzan@redhat.com>
---
src/conf/domain_conf.c | 29 +++++++++++++++++++++++++++++
src/conf/domain_conf.h | 3 +++
src/libvirt_private.syms | 1 +
3 files changed, 33 insertions(+)
diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c
index 396cd1c0dbc2..d2dea6952efc 100644
--- a/src/conf/domain_conf.c
+++ b/src/conf/domain_conf.c
@@ -20446,6 +20446,35 @@ virDomainDefParse(const char *xmlStr,
return virDomainDefParseNode(ctxt, xmlopt, parseOpaque, flags);
}
+virDomainDef *
+virDomainDefIDsParseString(const char *xmlStr,
+ virDomainXMLOption *xmlopt,
+ unsigned int flags)
+{
+ g_autoptr(virDomainDef) def = NULL;
+ g_autoptr(xmlDoc) xml = NULL;
+ g_autoptr(xmlXPathContext) ctxt = NULL;
+ bool uuid_generated = false;
+
+ xml = virXMLParseWithIndent(NULL, xmlStr, _("(domain_definition)"),
+ "domain", &ctxt, "domain.rng", false);
+
+ if (!xml)
+ return NULL;
+
+ def = virDomainDefNew(xmlopt);
+ if (!def)
+ return NULL;
+
+ if (virDomainDefParseIDs(def, ctxt, flags, &uuid_generated) < 0)
+ return NULL;
+
+ if (uuid_generated)
+ memset(def->uuid, 0, VIR_UUID_BUFLEN);
+
+ return g_steal_pointer(&def);
+}
+
virDomainDef *
virDomainDefParseString(const char *xmlStr,
virDomainXMLOption *xmlopt,
diff --git a/src/conf/domain_conf.h b/src/conf/domain_conf.h
index 81e735993d47..11eb46ae5385 100644
--- a/src/conf/domain_conf.h
+++ b/src/conf/domain_conf.h
@@ -3948,6 +3948,9 @@ virDomainDiskDef *virDomainDiskDefParse(const char *xmlStr,
virStorageSource *virDomainDiskDefParseSource(const char *xmlStr,
virDomainXMLOption *xmlopt,
unsigned int flags);
+virDomainDef * virDomainDefIDsParseString(const char *xmlStr,
+ virDomainXMLOption *xmlopt,
+ unsigned int flags);
virDomainDef *virDomainDefParseString(const char *xmlStr,
virDomainXMLOption *xmlopt,
void *parseOpaque,
diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms
index 7269dd37862d..fb482fff40a5 100644
--- a/src/libvirt_private.syms
+++ b/src/libvirt_private.syms
@@ -352,6 +352,7 @@ virDomainDefHasTimer;
virDomainDefHasUSB;
virDomainDefHasVcpusOffline;
virDomainDefHasVDPANet;
+virDomainDefIDsParseString;
virDomainDefLifecycleActionAllowed;
virDomainDefMaybeAddController;
virDomainDefMaybeAddInput;
--
2.51.2