[PATCH 05/11] conf: Disallow new qemu, lxc domains to use all white space as name

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



https://bugzilla.redhat.com/show_bug.cgi?id=1107420

Add a new define/create flag VIR_DOMAIN_DEF_PARSE_VALIDATE_NAME
to disallow new domains to be defined/created using a name
comprised entirely of spaces.

Alter the qemuxml2argvtest to add a test in order to prove the
failure occurs.

Signed-off-by: John Ferlan <jferlan@xxxxxxxxxx>
---
 src/conf/domain_conf.c                     |  7 ++++++
 src/conf/domain_conf.h                     |  4 +++
 src/lxc/lxc_driver.c                       |  6 +++--
 src/qemu/qemu_driver.c                     |  6 +++--
 tests/qemuxml2argvdata/name-whitespace.xml | 29 ++++++++++++++++++++++
 tests/qemuxml2argvtest.c                   |  5 +++-
 6 files changed, 52 insertions(+), 5 deletions(-)
 create mode 100644 tests/qemuxml2argvdata/name-whitespace.xml

diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c
index 705575fe92..6620ff89af 100644
--- a/src/conf/domain_conf.c
+++ b/src/conf/domain_conf.c
@@ -19278,6 +19278,13 @@ virDomainDefParseXML(xmlDocPtr xml,
         goto error;
     }
 
+    if ((flags & VIR_DOMAIN_DEF_PARSE_VALIDATE_NAME) &&
+        virStringIsEmpty(def->name)) {
+        virReportError(VIR_ERR_XML_ERROR, "%s",
+                       _("name must contain at least one non blank character"));
+        goto error;
+    }
+
     /* Extract domain uuid. If both uuid and sysinfo/system/entry/uuid
      * exist, they must match; and if only the latter exists, it can
      * also serve as the uuid. */
diff --git a/src/conf/domain_conf.h b/src/conf/domain_conf.h
index c1dfa37fdf..7eb020d6d7 100644
--- a/src/conf/domain_conf.h
+++ b/src/conf/domain_conf.h
@@ -2996,6 +2996,10 @@ typedef enum {
      * post parse callbacks before starting. Failure of the post parse callback
      * is recorded as def->postParseFail */
     VIR_DOMAIN_DEF_PARSE_ALLOW_POST_PARSE_FAIL = 1 << 12,
+    /* Perform extra name validation on new domain names which
+     * will cause failure to parse the XML. Initially just that a
+     * name cannot be all white space. */
+    VIR_DOMAIN_DEF_PARSE_VALIDATE_NAME = 1 << 13,
 } virDomainDefParseFlags;
 
 typedef enum {
diff --git a/src/lxc/lxc_driver.c b/src/lxc/lxc_driver.c
index 8867645cdc..5d1082292d 100644
--- a/src/lxc/lxc_driver.c
+++ b/src/lxc/lxc_driver.c
@@ -418,7 +418,8 @@ lxcDomainDefineXMLFlags(virConnectPtr conn, const char *xml, unsigned int flags)
     virDomainDefPtr oldDef = NULL;
     virLXCDriverConfigPtr cfg = virLXCDriverGetConfig(driver);
     virCapsPtr caps = NULL;
-    unsigned int parse_flags = VIR_DOMAIN_DEF_PARSE_INACTIVE;
+    unsigned int parse_flags = VIR_DOMAIN_DEF_PARSE_INACTIVE |
+                               VIR_DOMAIN_DEF_PARSE_VALIDATE_NAME;
 
     virCheckFlags(VIR_DOMAIN_DEFINE_VALIDATE, NULL);
 
@@ -1163,7 +1164,8 @@ lxcDomainCreateXMLWithFiles(virConnectPtr conn,
     virObjectEventPtr event = NULL;
     virLXCDriverConfigPtr cfg = virLXCDriverGetConfig(driver);
     virCapsPtr caps = NULL;
-    unsigned int parse_flags = VIR_DOMAIN_DEF_PARSE_INACTIVE;
+    unsigned int parse_flags = VIR_DOMAIN_DEF_PARSE_INACTIVE |
+                               VIR_DOMAIN_DEF_PARSE_VALIDATE_NAME;
 
     virCheckFlags(VIR_DOMAIN_START_AUTODESTROY |
                   VIR_DOMAIN_START_VALIDATE, NULL);
diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c
index fb0d4a8c7a..37f10d286e 100644
--- a/src/qemu/qemu_driver.c
+++ b/src/qemu/qemu_driver.c
@@ -1710,7 +1710,8 @@ static virDomainPtr qemuDomainCreateXML(virConnectPtr conn,
     unsigned int start_flags = VIR_QEMU_PROCESS_START_COLD;
     virCapsPtr caps = NULL;
     unsigned int parse_flags = VIR_DOMAIN_DEF_PARSE_INACTIVE |
-                               VIR_DOMAIN_DEF_PARSE_ABI_UPDATE;
+                               VIR_DOMAIN_DEF_PARSE_ABI_UPDATE |
+                               VIR_DOMAIN_DEF_PARSE_VALIDATE_NAME;
 
     virCheckFlags(VIR_DOMAIN_START_PAUSED |
                   VIR_DOMAIN_START_AUTODESTROY |
@@ -7381,7 +7382,8 @@ qemuDomainDefineXMLFlags(virConnectPtr conn,
     virQEMUDriverConfigPtr cfg;
     virCapsPtr caps = NULL;
     unsigned int parse_flags = VIR_DOMAIN_DEF_PARSE_INACTIVE |
-                               VIR_DOMAIN_DEF_PARSE_ABI_UPDATE;
+                               VIR_DOMAIN_DEF_PARSE_ABI_UPDATE |
+                               VIR_DOMAIN_DEF_PARSE_VALIDATE_NAME;
 
     virCheckFlags(VIR_DOMAIN_DEFINE_VALIDATE, NULL);
 
diff --git a/tests/qemuxml2argvdata/name-whitespace.xml b/tests/qemuxml2argvdata/name-whitespace.xml
new file mode 100644
index 0000000000..e143c7c770
--- /dev/null
+++ b/tests/qemuxml2argvdata/name-whitespace.xml
@@ -0,0 +1,29 @@
+<domain type='qemu'>
+  <name> </name>
+  <uuid>c7a5fdbd-edaf-9455-926a-d65c16db1809</uuid>
+  <memory unit='KiB'>219100</memory>
+  <currentMemory unit='KiB'>219100</currentMemory>
+  <vcpu placement='static' cpuset='1-4,8-20,525'>1</vcpu>
+  <os>
+    <type arch='i686' machine='pc'>hvm</type>
+    <boot dev='hd'/>
+  </os>
+  <clock offset='utc'/>
+  <on_poweroff>destroy</on_poweroff>
+  <on_reboot>restart</on_reboot>
+  <on_crash>destroy</on_crash>
+  <devices>
+    <emulator>/usr/bin/qemu-system-i686</emulator>
+    <disk type='block' device='disk'>
+      <source dev='/dev/HostVG/QEMUGuest1'/>
+      <target dev='hda' bus='ide'/>
+      <address type='drive' controller='0' bus='0' target='0' unit='0'/>
+    </disk>
+    <controller type='usb' index='0'/>
+    <controller type='ide' index='0'/>
+    <controller type='pci' index='0' model='pci-root'/>
+    <input type='mouse' bus='ps2'/>
+    <input type='keyboard' bus='ps2'/>
+    <memballoon model='virtio'/>
+  </devices>
+</domain>
diff --git a/tests/qemuxml2argvtest.c b/tests/qemuxml2argvtest.c
index 84117a3e63..e92bcd0df6 100644
--- a/tests/qemuxml2argvtest.c
+++ b/tests/qemuxml2argvtest.c
@@ -494,7 +494,8 @@ testCompareXMLToArgv(const void *data)
     if (!(vm = virDomainObjNew(driver.xmlopt)))
         goto cleanup;
 
-    parseFlags |= VIR_DOMAIN_DEF_PARSE_INACTIVE;
+    parseFlags |= VIR_DOMAIN_DEF_PARSE_INACTIVE |
+                  VIR_DOMAIN_DEF_PARSE_VALIDATE_NAME;
     if (!(vm->def = virDomainDefParseFile(xml, driver.caps, driver.xmlopt,
                                           NULL, parseFlags))) {
         if (flags & FLAG_EXPECT_PARSE_ERROR)
@@ -822,6 +823,8 @@ mymain(void)
     DO_TEST_PARSE_ERROR("minimal-no-memory", NONE);
     DO_TEST("minimal-msg-timestamp", QEMU_CAPS_MSG_TIMESTAMP);
 
+    DO_TEST_PARSE_ERROR("name-whitespace", NONE);
+
     DO_TEST_CAPS_LATEST("genid");
     DO_TEST_CAPS_LATEST("genid-auto");
 
-- 
2.17.1

--
libvir-list mailing list
libvir-list@xxxxxxxxxx
https://www.redhat.com/mailman/listinfo/libvir-list



[Index of Archives]     [Virt Tools]     [Libvirt Users]     [Lib OS Info]     [Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [KDE Users]     [Fedora Tools]

  Powered by Linux