]> xenbits.xensource.com Git - libvirt.git/commitdiff
conf: domain: reject name containing '/'
authorCole Robinson <crobinso@redhat.com>
Tue, 26 Apr 2016 15:23:12 +0000 (11:23 -0400)
committerCole Robinson <crobinso@redhat.com>
Mon, 2 May 2016 14:06:04 +0000 (10:06 -0400)
Trying to define a domain name containing an embedded '/'
will immediately fail when trying to write the XML to disk for
our stateful drivers. This patch explicitly rejects names
containing a '/', and provides an xmlopt feature for drivers
to avoid this validation check, which is enabled in every
non-stateful driver that already has xmlopt handling wired up.

(Technically this could reject a previously accepted vmname like
 '/foo', however at least for the qemu driver that falls over
 later when starting qemu)

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

src/conf/domain_conf.c
src/conf/domain_conf.h
src/openvz/openvz_driver.c
src/phyp/phyp_driver.c
src/vbox/vbox_common.c
src/vmx/vmx.c
src/xenapi/xenapi_driver.c
tests/genericxml2xmlindata/generic-name-slash-fail.xml [new file with mode: 0644]
tests/genericxml2xmltest.c

index 4853f741890e5c1a0688d20771f72e6383e60858..88e8d9f66f40382acd35bda5ffc50136854915e0 100644 (file)
@@ -4300,6 +4300,14 @@ virDomainDefPostParseCheckFeatures(virDomainDefPtr def,
     if (UNSUPPORTED(VIR_DOMAIN_DEF_FEATURE_OFFLINE_VCPUPIN))
         virDomainDefRemoveOfflineVcpuPin(def);
 
+    if (UNSUPPORTED(VIR_DOMAIN_DEF_FEATURE_NAME_SLASH)) {
+        if (def->name && strchr(def->name, '/')) {
+            virReportError(VIR_ERR_XML_ERROR,
+                           _("name %s cannot contain '/'"), def->name);
+            return -1;
+        }
+    }
+
     return 0;
 }
 
index 2cb9fa305d1e1606970504c8cf7b56d1300e255a..9f880b89e334e87d80b79e2e32d2492fee7f392a 100644 (file)
@@ -2444,6 +2444,7 @@ typedef enum {
     VIR_DOMAIN_DEF_FEATURE_WIDE_SCSI = (1 << 0),
     VIR_DOMAIN_DEF_FEATURE_MEMORY_HOTPLUG = (1 << 1),
     VIR_DOMAIN_DEF_FEATURE_OFFLINE_VCPUPIN = (1 << 2),
+    VIR_DOMAIN_DEF_FEATURE_NAME_SLASH = (1 << 3),
 } virDomainDefFeatures;
 
 
index e154a0f795d9817f46f1b8c842dad2bf021ef77f..a7474ff9fe1718bb4ac64fb44ec52561a11e2e1b 100644 (file)
@@ -128,8 +128,9 @@ openvzDomainDeviceDefPostParse(virDomainDeviceDefPtr dev,
 
 
 virDomainDefParserConfig openvzDomainDefParserConfig = {
-        .domainPostParseCallback = openvzDomainDefPostParse,
-        .devicesPostParseCallback = openvzDomainDeviceDefPostParse,
+    .domainPostParseCallback = openvzDomainDefPostParse,
+    .devicesPostParseCallback = openvzDomainDeviceDefPostParse,
+    .features = VIR_DOMAIN_DEF_FEATURE_NAME_SLASH,
 };
 
 
index 55a63e7130fa3a44d30416a0884428396a9b075d..da876865d51d3983d6116423420f41c235ac3df0 100644 (file)
@@ -1117,6 +1117,7 @@ phypDomainDeviceDefPostParse(virDomainDeviceDefPtr dev ATTRIBUTE_UNUSED,
 virDomainDefParserConfig virPhypDriverDomainDefParserConfig = {
     .devicesPostParseCallback = phypDomainDeviceDefPostParse,
     .domainPostParseCallback = phypDomainDefPostParse,
+    .features = VIR_DOMAIN_DEF_FEATURE_NAME_SLASH,
 };
 
 
index ab2297bd375f30cafbd2638581bf166a19145335..ed22724779bc599eefbc74721b20afb32c75db7d 100644 (file)
@@ -273,6 +273,7 @@ static virDomainDefParserConfig vboxDomainDefParserConfig = {
     .macPrefix = { 0x08, 0x00, 0x27 },
     .devicesPostParseCallback = vboxDomainDeviceDefPostParse,
     .domainPostParseCallback = vboxDomainDefPostParse,
+    .features = VIR_DOMAIN_DEF_FEATURE_NAME_SLASH,
 };
 
 static virDomainXMLOptionPtr
index 8c4b4bbc652aee12e7363315522254e8f2c3035f..5e57c3902ee835eda176f3577e712a5633a95c56 100644 (file)
@@ -547,7 +547,8 @@ static virDomainDefParserConfig virVMXDomainDefParserConfig = {
     .macPrefix = {0x00, 0x0c, 0x29},
     .devicesPostParseCallback = virVMXDomainDevicesDefPostParse,
     .domainPostParseCallback = virVMXDomainDefPostParse,
-    .features = VIR_DOMAIN_DEF_FEATURE_WIDE_SCSI,
+    .features = (VIR_DOMAIN_DEF_FEATURE_WIDE_SCSI |
+                 VIR_DOMAIN_DEF_FEATURE_NAME_SLASH),
 };
 
 static void
index a75a4f7a30ccc811963c169f9a6995f0bbeeee03..97a1adaa1b1a46fb4c95f8c09678975ea3c558b7 100644 (file)
@@ -88,6 +88,7 @@ xenapiDomainDefPostParse(virDomainDefPtr def,
 virDomainDefParserConfig xenapiDomainDefParserConfig = {
     .devicesPostParseCallback = xenapiDomainDeviceDefPostParse,
     .domainPostParseCallback = xenapiDomainDefPostParse,
+    .features = VIR_DOMAIN_DEF_FEATURE_NAME_SLASH,
 };
 
 
diff --git a/tests/genericxml2xmlindata/generic-name-slash-fail.xml b/tests/genericxml2xmlindata/generic-name-slash-fail.xml
new file mode 100644 (file)
index 0000000..4cdb834
--- /dev/null
@@ -0,0 +1,17 @@
+<domain type='qemu'>
+  <name>foo/bar</name>
+  <uuid>c7a5fdbd-edaf-9455-926a-d65c16db1809</uuid>
+  <memory unit='KiB'>219136</memory>
+  <currentMemory unit='KiB'>219136</currentMemory>
+  <vcpu placement='static'>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>
+  </devices>
+</domain>
index 05563fbfb98d0ae0457c314380ab0d29020ec20d..70a5203113bb73a120473a111a246e5812e9ab09 100644 (file)
@@ -81,6 +81,9 @@ mymain(void)
     DO_TEST_FULL("graphics-listen-back-compat-mismatch", 0, false,
         TEST_COMPARE_DOM_XML2XML_RESULT_FAIL_PARSE);
 
+    DO_TEST_FULL("name-slash-parse", 0, false,
+        TEST_COMPARE_DOM_XML2XML_RESULT_FAIL_PARSE);
+
     virObjectUnref(caps);
     virObjectUnref(xmlopt);