From: Sławek Kapłoński Date: Fri, 11 Nov 2016 09:17:37 +0000 (+0100) Subject: Forbid new-line char in name of new domain X-Git-Url: http://xenbits.xensource.com/gitweb?a=commitdiff_plain;h=6c98ac2c62c0801e8ba54915031292d9e5802424;p=libvirt.git Forbid new-line char in name of new domain New line character in name of domain is now forbidden because it mess virsh output and can be confusing for users. Validation of name is done in drivers, after parsing XML to avoid problems with dissappeared domains which was already created with new-line char in name. Signed-off-by: Michal Privoznik --- diff --git a/src/bhyve/bhyve_driver.c b/src/bhyve/bhyve_driver.c index 38fb9f0593..17f85245d1 100644 --- a/src/bhyve/bhyve_driver.c +++ b/src/bhyve/bhyve_driver.c @@ -541,6 +541,9 @@ bhyveDomainDefineXMLFlags(virConnectPtr conn, const char *xml, unsigned int flag NULL, parse_flags)) == NULL) goto cleanup; + if (virXMLCheckIllegalChars("name", def->name, "\n") < 0) + goto cleanup; + if (virDomainDefineXMLFlagsEnsureACL(conn, def) < 0) goto cleanup; diff --git a/src/esx/esx_driver.c b/src/esx/esx_driver.c index 17ef00fd97..166d4bcfcc 100644 --- a/src/esx/esx_driver.c +++ b/src/esx/esx_driver.c @@ -3051,6 +3051,9 @@ esxDomainDefineXMLFlags(virConnectPtr conn, const char *xml, unsigned int flags) if (!def) return NULL; + if (virXMLCheckIllegalChars("name", def->name, "\n") < 0) + goto cleanup; + /* Check if an existing domain should be edited */ if (esxVI_LookupVirtualMachineByUuid(priv->primary, def->uuid, NULL, &virtualMachine, diff --git a/src/libxl/libxl_driver.c b/src/libxl/libxl_driver.c index b2f3b162de..3efa91eee8 100644 --- a/src/libxl/libxl_driver.c +++ b/src/libxl/libxl_driver.c @@ -2791,6 +2791,9 @@ libxlDomainDefineXMLFlags(virConnectPtr conn, const char *xml, unsigned int flag NULL, parse_flags))) goto cleanup; + if (virXMLCheckIllegalChars("name", def->name, "\n") < 0) + goto cleanup; + if (virDomainDefineXMLFlagsEnsureACL(conn, def) < 0) goto cleanup; diff --git a/src/lxc/lxc_driver.c b/src/lxc/lxc_driver.c index 4a0165a616..a6776a1933 100644 --- a/src/lxc/lxc_driver.c +++ b/src/lxc/lxc_driver.c @@ -475,6 +475,9 @@ lxcDomainDefineXMLFlags(virConnectPtr conn, const char *xml, unsigned int flags) NULL, parse_flags))) goto cleanup; + if (virXMLCheckIllegalChars("name", def->name, "\n") < 0) + goto cleanup; + if (virDomainDefineXMLFlagsEnsureACL(conn, def) < 0) goto cleanup; diff --git a/src/openvz/openvz_driver.c b/src/openvz/openvz_driver.c index 38a562ed5d..1dfb1ccf49 100644 --- a/src/openvz/openvz_driver.c +++ b/src/openvz/openvz_driver.c @@ -1000,6 +1000,9 @@ openvzDomainDefineXMLFlags(virConnectPtr conn, const char *xml, unsigned int fla NULL, parse_flags)) == NULL) goto cleanup; + if (virXMLCheckIllegalChars("name", vmdef->name, "\n") < 0) + goto cleanup; + if (!(vm = virDomainObjListAdd(driver->domains, vmdef, driver->xmlopt, 0, NULL))) diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c index d039255beb..5ee3f93f9e 100644 --- a/src/qemu/qemu_driver.c +++ b/src/qemu/qemu_driver.c @@ -7339,6 +7339,9 @@ qemuDomainDefineXMLFlags(virConnectPtr conn, NULL, parse_flags))) goto cleanup; + if (virXMLCheckIllegalChars("name", def->name, "\n") < 0) + goto cleanup; + if (virDomainDefineXMLFlagsEnsureACL(conn, def) < 0) goto cleanup; diff --git a/src/test/test_driver.c b/src/test/test_driver.c index cc300f0e83..9eff82c129 100644 --- a/src/test/test_driver.c +++ b/src/test/test_driver.c @@ -2641,6 +2641,9 @@ static virDomainPtr testDomainDefineXMLFlags(virConnectPtr conn, NULL, parse_flags)) == NULL) goto cleanup; + if (virXMLCheckIllegalChars("name", def->name, "\n") < 0) + goto cleanup; + if (testDomainGenerateIfnames(def) < 0) goto cleanup; if (!(dom = virDomainObjListAdd(privconn->domains, diff --git a/src/uml/uml_driver.c b/src/uml/uml_driver.c index 4f4a69be4a..ad89e3ef7f 100644 --- a/src/uml/uml_driver.c +++ b/src/uml/uml_driver.c @@ -2074,6 +2074,9 @@ umlDomainDefineXMLFlags(virConnectPtr conn, const char *xml, unsigned int flags) NULL, parse_flags))) goto cleanup; + if (virXMLCheckIllegalChars("name", def->name, "\n") < 0) + goto cleanup; + if (virDomainDefineXMLFlagsEnsureACL(conn, def) < 0) goto cleanup; diff --git a/src/vmware/vmware_driver.c b/src/vmware/vmware_driver.c index 9a53b8da7b..d3497bd2d5 100644 --- a/src/vmware/vmware_driver.c +++ b/src/vmware/vmware_driver.c @@ -392,6 +392,9 @@ vmwareDomainDefineXMLFlags(virConnectPtr conn, const char *xml, unsigned int fla NULL, parse_flags)) == NULL) goto cleanup; + if (virXMLCheckIllegalChars("name", vmdef->name, "\n") < 0) + goto cleanup; + /* generate vmx file */ vmx = virVMXFormatConfig(&ctx, driver->xmlopt, vmdef, 7); if (vmx == NULL) diff --git a/src/vz/vz_driver.c b/src/vz/vz_driver.c index b2c3e31c5f..08f7961235 100644 --- a/src/vz/vz_driver.c +++ b/src/vz/vz_driver.c @@ -854,6 +854,9 @@ vzDomainDefineXMLFlags(virConnectPtr conn, const char *xml, unsigned int flags) NULL, parse_flags)) == NULL) goto cleanup; + if (virXMLCheckIllegalChars("name", def->name, "\n") < 0) + goto cleanup; + if (virDomainDefineXMLFlagsEnsureACL(conn, def) < 0) goto cleanup; diff --git a/src/xen/xen_driver.c b/src/xen/xen_driver.c index 188c2d1e25..3f9bfa7a6c 100644 --- a/src/xen/xen_driver.c +++ b/src/xen/xen_driver.c @@ -1810,6 +1810,9 @@ xenUnifiedDomainDefineXMLFlags(virConnectPtr conn, const char *xml, unsigned int NULL, parse_flags))) goto cleanup; + if (virXMLCheckIllegalChars("name", def->name, "\n") < 0) + goto cleanup; + if (virDomainDefineXMLFlagsEnsureACL(conn, def) < 0) goto cleanup; diff --git a/src/xenapi/xenapi_driver.c b/src/xenapi/xenapi_driver.c index dcb79aa713..a9ed407bc5 100644 --- a/src/xenapi/xenapi_driver.c +++ b/src/xenapi/xenapi_driver.c @@ -1759,6 +1759,11 @@ xenapiDomainDefineXMLFlags(virConnectPtr conn, const char *xml, unsigned int fla if (!defPtr) return NULL; + if (virXMLCheckIllegalChars("name", defPtr->name, "\n") < 0) { + virDomainDefFree(defPtr); + return NULL; + } + if (createVMRecordFromXml(conn, defPtr, &record, &vm) != 0) { if (!priv->session->ok) xenapiSessionErrorHandler(conn, VIR_ERR_INTERNAL_ERROR, NULL);