1
0
mirror of https://gitlab.com/libvirt/libvirt.git synced 2024-12-22 17:34:18 +03:00

conf: domain: reject name containing '/'

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
This commit is contained in:
Cole Robinson 2016-04-26 11:23:12 -04:00
parent 541f21afa6
commit b1fc6a7b73
9 changed files with 37 additions and 3 deletions

View File

@ -4300,6 +4300,14 @@ virDomainDefPostParseCheckFeatures(virDomainDefPtr def,
if (UNSUPPORTED(VIR_DOMAIN_DEF_FEATURE_OFFLINE_VCPUPIN)) if (UNSUPPORTED(VIR_DOMAIN_DEF_FEATURE_OFFLINE_VCPUPIN))
virDomainDefRemoveOfflineVcpuPin(def); 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; return 0;
} }

View File

@ -2444,6 +2444,7 @@ typedef enum {
VIR_DOMAIN_DEF_FEATURE_WIDE_SCSI = (1 << 0), VIR_DOMAIN_DEF_FEATURE_WIDE_SCSI = (1 << 0),
VIR_DOMAIN_DEF_FEATURE_MEMORY_HOTPLUG = (1 << 1), VIR_DOMAIN_DEF_FEATURE_MEMORY_HOTPLUG = (1 << 1),
VIR_DOMAIN_DEF_FEATURE_OFFLINE_VCPUPIN = (1 << 2), VIR_DOMAIN_DEF_FEATURE_OFFLINE_VCPUPIN = (1 << 2),
VIR_DOMAIN_DEF_FEATURE_NAME_SLASH = (1 << 3),
} virDomainDefFeatures; } virDomainDefFeatures;

View File

@ -128,8 +128,9 @@ openvzDomainDeviceDefPostParse(virDomainDeviceDefPtr dev,
virDomainDefParserConfig openvzDomainDefParserConfig = { virDomainDefParserConfig openvzDomainDefParserConfig = {
.domainPostParseCallback = openvzDomainDefPostParse, .domainPostParseCallback = openvzDomainDefPostParse,
.devicesPostParseCallback = openvzDomainDeviceDefPostParse, .devicesPostParseCallback = openvzDomainDeviceDefPostParse,
.features = VIR_DOMAIN_DEF_FEATURE_NAME_SLASH,
}; };

View File

@ -1117,6 +1117,7 @@ phypDomainDeviceDefPostParse(virDomainDeviceDefPtr dev ATTRIBUTE_UNUSED,
virDomainDefParserConfig virPhypDriverDomainDefParserConfig = { virDomainDefParserConfig virPhypDriverDomainDefParserConfig = {
.devicesPostParseCallback = phypDomainDeviceDefPostParse, .devicesPostParseCallback = phypDomainDeviceDefPostParse,
.domainPostParseCallback = phypDomainDefPostParse, .domainPostParseCallback = phypDomainDefPostParse,
.features = VIR_DOMAIN_DEF_FEATURE_NAME_SLASH,
}; };

View File

@ -273,6 +273,7 @@ static virDomainDefParserConfig vboxDomainDefParserConfig = {
.macPrefix = { 0x08, 0x00, 0x27 }, .macPrefix = { 0x08, 0x00, 0x27 },
.devicesPostParseCallback = vboxDomainDeviceDefPostParse, .devicesPostParseCallback = vboxDomainDeviceDefPostParse,
.domainPostParseCallback = vboxDomainDefPostParse, .domainPostParseCallback = vboxDomainDefPostParse,
.features = VIR_DOMAIN_DEF_FEATURE_NAME_SLASH,
}; };
static virDomainXMLOptionPtr static virDomainXMLOptionPtr

View File

@ -547,7 +547,8 @@ static virDomainDefParserConfig virVMXDomainDefParserConfig = {
.macPrefix = {0x00, 0x0c, 0x29}, .macPrefix = {0x00, 0x0c, 0x29},
.devicesPostParseCallback = virVMXDomainDevicesDefPostParse, .devicesPostParseCallback = virVMXDomainDevicesDefPostParse,
.domainPostParseCallback = virVMXDomainDefPostParse, .domainPostParseCallback = virVMXDomainDefPostParse,
.features = VIR_DOMAIN_DEF_FEATURE_WIDE_SCSI, .features = (VIR_DOMAIN_DEF_FEATURE_WIDE_SCSI |
VIR_DOMAIN_DEF_FEATURE_NAME_SLASH),
}; };
static void static void

View File

@ -88,6 +88,7 @@ xenapiDomainDefPostParse(virDomainDefPtr def,
virDomainDefParserConfig xenapiDomainDefParserConfig = { virDomainDefParserConfig xenapiDomainDefParserConfig = {
.devicesPostParseCallback = xenapiDomainDeviceDefPostParse, .devicesPostParseCallback = xenapiDomainDeviceDefPostParse,
.domainPostParseCallback = xenapiDomainDefPostParse, .domainPostParseCallback = xenapiDomainDefPostParse,
.features = VIR_DOMAIN_DEF_FEATURE_NAME_SLASH,
}; };

View File

@ -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>

View File

@ -81,6 +81,9 @@ mymain(void)
DO_TEST_FULL("graphics-listen-back-compat-mismatch", 0, false, DO_TEST_FULL("graphics-listen-back-compat-mismatch", 0, false,
TEST_COMPARE_DOM_XML2XML_RESULT_FAIL_PARSE); 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(caps);
virObjectUnref(xmlopt); virObjectUnref(xmlopt);