The previous patches only cleaned up ATTRIBUTE_UNUSED flags cases;
auditing the drivers found other places where flags was being used
but not validated. In particular, domainGetXMLDesc had issues with
clients accepting a different set of flags than the common
virDomainDefFormat helper function.
* src/conf/domain_conf.c (virDomainDefFormat): Add common flag check.
* src/storage/storage_driver.c (storageVolumeCreateXMLFrom): Pass
0 to drivers, since all flags are currently rejected.
* src/uml/uml_driver.c (umlDomainAttachDeviceFlags)
(umlDomainDetachDeviceFlags): Reject unknown
flags.
* src/vbox/vbox_tmpl.c (vboxDomainGetXMLDesc)
(vboxDomainAttachDeviceFlags)
(vboxDomainDetachDeviceFlags): Likewise.
* src/qemu/qemu_driver.c (qemudDomainMemoryPeek): Likewise.
(qemuDomainGetXMLDesc): Document common flag handling.
* src/libxl/libxl_driver.c (libxlDomainGetXMLDesc): Likewise.
* src/lxc/lxc_driver.c (lxcDomainGetXMLDesc): Likewise.
* src/openvz/openvz_driver.c (openvzDomainGetXMLDesc): Likewise.
* src/phyp/phyp_driver.c (phypDomainGetXMLDesc): Likewise.
* src/test/test_driver.c (testDomainGetXMLDesc): Likewise.
* src/vmware/vmware_driver.c (vmwareDomainGetXMLDesc): Likewise.
* src/xenapi/xenapi_driver.c (xenapiDomainGetXMLDesc): Likewise.
---
v3: new patch
src/conf/domain_conf.c | 4 ++++
src/libxl/libxl_driver.c | 2 ++
src/lxc/lxc_driver.c | 2 ++
src/openvz/openvz_driver.c | 2 ++
src/phyp/phyp_driver.c | 2 ++
src/qemu/qemu_driver.c | 6 +++---
src/storage/storage_driver.c | 2 +-
src/test/test_driver.c | 2 ++
src/uml/uml_driver.c | 24 +++++++++++++++---------
src/vbox/vbox_tmpl.c | 18 ++++++++++++++----
src/vmware/vmware_driver.c | 2 ++
src/xenapi/xenapi_driver.c | 4 +---
12 files changed, 50 insertions(+), 20 deletions(-)
diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c
index a78996f..788981f 100644
--- a/src/conf/domain_conf.c
+++ b/src/conf/domain_conf.c
@@ -9624,6 +9624,10 @@ char *virDomainDefFormat(virDomainDefPtr def,
const char *type = NULL;
int n, allones = 1;
+ virCheckFlags(VIR_DOMAIN_XML_SECURE |
+ VIR_DOMAIN_XML_INACTIVE |
+ VIR_DOMAIN_XML_UPDATE_CPU, NULL);
+
if (!(type = virDomainVirtTypeToString(def->virtType))) {
virDomainReportError(VIR_ERR_INTERNAL_ERROR,
_("unexpected domain type %d"), def->virtType);
diff --git a/src/libxl/libxl_driver.c b/src/libxl/libxl_driver.c
index f938e24..cc37d05 100644
--- a/src/libxl/libxl_driver.c
+++ b/src/libxl/libxl_driver.c
@@ -2494,6 +2494,8 @@ libxlDomainGetXMLDesc(virDomainPtr dom, unsigned int flags)
virDomainObjPtr vm;
char *ret = NULL;
+ /* Flags checked by virDomainDefFormat */
+
libxlDriverLock(driver);
vm = virDomainFindByUUID(&driver->domains, dom->uuid);
libxlDriverUnlock(driver);
diff --git a/src/lxc/lxc_driver.c b/src/lxc/lxc_driver.c
index b6da757..78f0f9d 100644
--- a/src/lxc/lxc_driver.c
+++ b/src/lxc/lxc_driver.c
@@ -967,6 +967,8 @@ static char *lxcDomainGetXMLDesc(virDomainPtr dom,
virDomainObjPtr vm;
char *ret = NULL;
+ /* Flags checked by virDomainDefFormat */
+
lxcDriverLock(driver);
vm = virDomainFindByUUID(&driver->domains, dom->uuid);
lxcDriverUnlock(driver);
diff --git a/src/openvz/openvz_driver.c b/src/openvz/openvz_driver.c
index d50ecf1..cc0c590 100644
--- a/src/openvz/openvz_driver.c
+++ b/src/openvz/openvz_driver.c
@@ -461,6 +461,8 @@ static char *openvzDomainGetXMLDesc(virDomainPtr dom, unsigned int
flags) {
virDomainObjPtr vm;
char *ret = NULL;
+ /* Flags checked by virDomainDefFormat */
+
openvzDriverLock(driver);
vm = virDomainFindByUUID(&driver->domains, dom->uuid);
openvzDriverUnlock(driver);
diff --git a/src/phyp/phyp_driver.c b/src/phyp/phyp_driver.c
index 62ba192..2489063 100644
--- a/src/phyp/phyp_driver.c
+++ b/src/phyp/phyp_driver.c
@@ -3317,6 +3317,8 @@ phypDomainGetXMLDesc(virDomainPtr dom, unsigned int flags)
virDomainDef def;
char *managed_system = phyp_driver->managed_system;
+ /* Flags checked by virDomainDefFormat */
+
memset(&def, 0, sizeof(virDomainDef));
def.virtType = VIR_DOMAIN_VIRT_PHYP;
diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c
index 3d4207e..c0acf52 100644
--- a/src/qemu/qemu_driver.c
+++ b/src/qemu/qemu_driver.c
@@ -3840,9 +3840,7 @@ static char *qemuDomainGetXMLDesc(virDomainPtr dom,
unsigned long balloon;
int err;
- virCheckFlags(VIR_DOMAIN_XML_SECURE |
- VIR_DOMAIN_XML_INACTIVE |
- VIR_DOMAIN_XML_UPDATE_CPU, NULL);
+ /* Flags checked by virDomainDefFormat */
qemuDriverLock(driver);
vm = virDomainFindByUUID(&driver->domains, dom->uuid);
@@ -6273,6 +6271,8 @@ qemudDomainMemoryPeek (virDomainPtr dom,
int fd = -1, ret = -1;
qemuDomainObjPrivatePtr priv;
+ virCheckFlags(VIR_MEMORY_VIRTUAL | VIR_MEMORY_PHYSICAL, -1);
+
qemuDriverLock(driver);
vm = virDomainFindByUUID(&driver->domains, dom->uuid);
qemuDriverUnlock(driver);
diff --git a/src/storage/storage_driver.c b/src/storage/storage_driver.c
index 4f35be0..419df42 100644
--- a/src/storage/storage_driver.c
+++ b/src/storage/storage_driver.c
@@ -1522,7 +1522,7 @@ storageVolumeCreateXMLFrom(virStoragePoolPtr obj,
virStoragePoolObjUnlock(origpool);
}
- buildret = backend->buildVolFrom(obj->conn, pool, newvol, origvol, flags);
+ buildret = backend->buildVolFrom(obj->conn, pool, newvol, origvol, 0);
storageDriverLock(driver);
virStoragePoolObjLock(pool);
diff --git a/src/test/test_driver.c b/src/test/test_driver.c
index f3fb320..064a1cd 100644
--- a/src/test/test_driver.c
+++ b/src/test/test_driver.c
@@ -2366,6 +2366,8 @@ static char *testDomainGetXMLDesc(virDomainPtr domain, unsigned int
flags)
virDomainObjPtr privdom;
char *ret = NULL;
+ /* Flags checked by virDomainDefFormat */
+
testDriverLock(privconn);
privdom = virDomainFindByName(&privconn->domains,
domain->name);
diff --git a/src/uml/uml_driver.c b/src/uml/uml_driver.c
index 6eede55..0f4f60e 100644
--- a/src/uml/uml_driver.c
+++ b/src/uml/uml_driver.c
@@ -1586,9 +1586,7 @@ static char *umlDomainGetXMLDesc(virDomainPtr dom,
virDomainObjPtr vm;
char *ret = NULL;
- virCheckFlags(VIR_DOMAIN_XML_SECURE |
- VIR_DOMAIN_XML_INACTIVE |
- VIR_DOMAIN_XML_UPDATE_CPU, NULL);
+ /* Flags checked by virDomainDefFormat */
umlDriverLock(driver);
vm = virDomainFindByUUID(&driver->domains, dom->uuid);
@@ -1855,9 +1853,13 @@ cleanup:
}
-static int umlDomainAttachDeviceFlags(virDomainPtr dom,
- const char *xml,
- unsigned int flags) {
+static int
+umlDomainAttachDeviceFlags(virDomainPtr dom,
+ const char *xml,
+ unsigned int flags)
+{
+ virCheckFlags(VIR_DOMAIN_AFFECT_LIVE | VIR_DOMAIN_AFFECT_CONFIG, -1);
+
if (flags & VIR_DOMAIN_AFFECT_CONFIG) {
umlReportError(VIR_ERR_OPERATION_INVALID,
"%s", _("cannot modify the persistent configuration
of a domain"));
@@ -1963,9 +1965,13 @@ cleanup:
}
-static int umlDomainDetachDeviceFlags(virDomainPtr dom,
- const char *xml,
- unsigned int flags) {
+static int
+umlDomainDetachDeviceFlags(virDomainPtr dom,
+ const char *xml,
+ unsigned int flags)
+{
+ virCheckFlags(VIR_DOMAIN_AFFECT_LIVE | VIR_DOMAIN_AFFECT_CONFIG, -1);
+
if (flags & VIR_DOMAIN_AFFECT_CONFIG) {
umlReportError(VIR_ERR_OPERATION_INVALID,
"%s", _("cannot modify the persistent configuration
of a domain"));
diff --git a/src/vbox/vbox_tmpl.c b/src/vbox/vbox_tmpl.c
index 6cb9bb4..53bac79 100644
--- a/src/vbox/vbox_tmpl.c
+++ b/src/vbox/vbox_tmpl.c
@@ -2145,6 +2145,8 @@ static char *vboxDomainGetXMLDesc(virDomainPtr dom, unsigned int
flags) {
nsresult rc;
char *tmp;
+ /* Flags checked by virDomainDefFormat */
+
if (VIR_ALLOC(def) < 0) {
virReportOOMError();
goto cleanup;
@@ -5296,8 +5298,12 @@ static int vboxDomainAttachDevice(virDomainPtr dom, const char
*xml) {
return vboxDomainAttachDeviceImpl(dom, xml, 0);
}
-static int vboxDomainAttachDeviceFlags(virDomainPtr dom, const char *xml,
- unsigned int flags) {
+static int
+vboxDomainAttachDeviceFlags(virDomainPtr dom, const char *xml,
+ unsigned int flags)
+{
+ virCheckFlags(VIR_DOMAIN_AFFECT_LIVE | VIR_DOMAIN_AFFECT_CONFIG, -1);
+
if (flags & VIR_DOMAIN_AFFECT_CONFIG) {
vboxError(VIR_ERR_OPERATION_INVALID, "%s",
_("cannot modify the persistent configuration of a
domain"));
@@ -5446,8 +5452,12 @@ cleanup:
return ret;
}
-static int vboxDomainDetachDeviceFlags(virDomainPtr dom, const char *xml,
- unsigned int flags) {
+static int
+vboxDomainDetachDeviceFlags(virDomainPtr dom, const char *xml,
+ unsigned int flags)
+{
+ virCheckFlags(VIR_DOMAIN_AFFECT_LIVE | VIR_DOMAIN_AFFECT_CONFIG, -1);
+
if (flags & VIR_DOMAIN_AFFECT_CONFIG) {
vboxError(VIR_ERR_OPERATION_INVALID, "%s",
_("cannot modify the persistent configuration of a
domain"));
diff --git a/src/vmware/vmware_driver.c b/src/vmware/vmware_driver.c
index c0430fe..36b48e0 100644
--- a/src/vmware/vmware_driver.c
+++ b/src/vmware/vmware_driver.c
@@ -807,6 +807,8 @@ vmwareDomainGetXMLDesc(virDomainPtr dom, unsigned int flags)
virDomainObjPtr vm;
char *ret = NULL;
+ /* Flags checked by virDomainDefFormat */
+
vmwareDriverLock(driver);
vm = virDomainFindByUUID(&driver->domains, dom->uuid);
vmwareDriverUnlock(driver);
diff --git a/src/xenapi/xenapi_driver.c b/src/xenapi/xenapi_driver.c
index 98838e6..97da1d1 100644
--- a/src/xenapi/xenapi_driver.c
+++ b/src/xenapi/xenapi_driver.c
@@ -1318,9 +1318,7 @@ xenapiDomainGetXMLDesc(virDomainPtr dom, unsigned int flags)
struct xen_vif_set *vif_set = NULL;
char *xml;
- virCheckFlags(VIR_DOMAIN_XML_SECURE |
- VIR_DOMAIN_XML_INACTIVE |
- VIR_DOMAIN_XML_UPDATE_CPU, NULL);
+ /* Flags checked by virDomainDefFormat */
if (!xen_vm_get_by_name_label(session, &vms, dom->name)) return NULL;
if (vms->size != 1) {
--
1.7.4.4