[libvirt] [PATCH 0/2] Forbid new-line char in name of domains and storagepools

As https://bugzilla.redhat.com/show_bug.cgi?id=818064 is closed and new-line char is now forbiden in name of network, this patch forbids it also in names of domains and storage pools. Sławek Kapłoński (2): Forbid new-line char in name of new domain Forbid new-line char in name of new storagepool src/bhyve/bhyve_driver.c | 3 +++ src/esx/esx_driver.c | 3 +++ src/libxl/libxl_driver.c | 3 +++ src/lxc/lxc_driver.c | 3 +++ src/openvz/openvz_driver.c | 3 +++ src/qemu/qemu_driver.c | 3 +++ src/storage/storage_driver.c | 3 +++ src/test/test_driver.c | 3 +++ src/uml/uml_driver.c | 3 +++ src/vmware/vmware_driver.c | 3 +++ src/vz/vz_driver.c | 3 +++ src/xen/xen_driver.c | 3 +++ src/xenapi/xenapi_driver.c | 3 +++ 13 files changed, 39 insertions(+) -- 2.7.4

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. --- src/bhyve/bhyve_driver.c | 3 +++ src/esx/esx_driver.c | 3 +++ src/libxl/libxl_driver.c | 3 +++ src/lxc/lxc_driver.c | 3 +++ src/openvz/openvz_driver.c | 3 +++ src/qemu/qemu_driver.c | 3 +++ src/test/test_driver.c | 3 +++ src/uml/uml_driver.c | 3 +++ src/vmware/vmware_driver.c | 3 +++ src/vz/vz_driver.c | 3 +++ src/xen/xen_driver.c | 3 +++ src/xenapi/xenapi_driver.c | 3 +++ 12 files changed, 36 insertions(+) diff --git a/src/bhyve/bhyve_driver.c b/src/bhyve/bhyve_driver.c index 38fb9f0..17f8524 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 17ef00f..166d4bc 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 b2f3b16..3efa91e 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 4a0165a..a6776a1 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 38a562e..1dfb1cc 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 a82e58b..8d337eb 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 236874f..1b54839 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 4f4a69b..ad89e3e 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 9a53b8d..d3497bd 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 b7c37bb..7cd89a0 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 188c2d1..3f9bfa7 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 dcb79aa..eedfc17 100644 --- a/src/xenapi/xenapi_driver.c +++ b/src/xenapi/xenapi_driver.c @@ -1759,6 +1759,9 @@ xenapiDomainDefineXMLFlags(virConnectPtr conn, const char *xml, unsigned int fla if (!defPtr) return NULL; + if (virXMLCheckIllegalChars("name", defPtr->name, "\n") < 0) + goto cleanup; + if (createVMRecordFromXml(conn, defPtr, &record, &vm) != 0) { if (!priv->session->ok) xenapiSessionErrorHandler(conn, VIR_ERR_INTERNAL_ERROR, NULL); -- 2.7.4

On 11.11.2016 10:17, Sławek Kapłoński wrote:
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. --- src/bhyve/bhyve_driver.c | 3 +++ src/esx/esx_driver.c | 3 +++ src/libxl/libxl_driver.c | 3 +++ src/lxc/lxc_driver.c | 3 +++ src/openvz/openvz_driver.c | 3 +++ src/qemu/qemu_driver.c | 3 +++ src/test/test_driver.c | 3 +++ src/uml/uml_driver.c | 3 +++ src/vmware/vmware_driver.c | 3 +++ src/vz/vz_driver.c | 3 +++ src/xen/xen_driver.c | 3 +++ src/xenapi/xenapi_driver.c | 3 +++ 12 files changed, 36 insertions(+)
diff --git a/src/bhyve/bhyve_driver.c b/src/bhyve/bhyve_driver.c index 38fb9f0..17f8524 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 17ef00f..166d4bc 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 b2f3b16..3efa91e 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 4a0165a..a6776a1 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 38a562e..1dfb1cc 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 a82e58b..8d337eb 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 236874f..1b54839 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 4f4a69b..ad89e3e 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 9a53b8d..d3497bd 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 b7c37bb..7cd89a0 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 188c2d1..3f9bfa7 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 dcb79aa..eedfc17 100644 --- a/src/xenapi/xenapi_driver.c +++ b/src/xenapi/xenapi_driver.c @@ -1759,6 +1759,9 @@ xenapiDomainDefineXMLFlags(virConnectPtr conn, const char *xml, unsigned int fla if (!defPtr) return NULL;
+ if (virXMLCheckIllegalChars("name", defPtr->name, "\n") < 0) + goto cleanup; +
This breaks the build. There's no cleanup label.
if (createVMRecordFromXml(conn, defPtr, &record, &vm) != 0) { if (!priv->session->ok) xenapiSessionErrorHandler(conn, VIR_ERR_INTERNAL_ERROR, NULL);
Michal

New line character in name of storagepool is now forbidden because it mess virsh output and can be confusing for users. Validation of name is done in driver, after parsing XML to avoid problems with dissappeared pools which was already created with new-line char in name. --- src/storage/storage_driver.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/storage/storage_driver.c b/src/storage/storage_driver.c index 4f990f4..9900596 100644 --- a/src/storage/storage_driver.c +++ b/src/storage/storage_driver.c @@ -780,6 +780,9 @@ storagePoolDefineXML(virConnectPtr conn, if (!(def = virStoragePoolDefParseString(xml))) goto cleanup; + if (virXMLCheckIllegalChars("name", def->name, "\n") < 0) + goto cleanup; + if (virStoragePoolDefineXMLEnsureACL(conn, def) < 0) goto cleanup; -- 2.7.4

Hello, Can someone review this patch maybe? Thx in advance :) -- Best regards / Pozdrawiam Sławek Kapłoński slawek@kaplonski.pl On Fri, 11 Nov 2016, Sławek Kapłoński wrote:
As https://bugzilla.redhat.com/show_bug.cgi?id=818064 is closed and new-line char is now forbiden in name of network, this patch forbids it also in names of domains and storage pools.
Sławek Kapłoński (2): Forbid new-line char in name of new domain Forbid new-line char in name of new storagepool
src/bhyve/bhyve_driver.c | 3 +++ src/esx/esx_driver.c | 3 +++ src/libxl/libxl_driver.c | 3 +++ src/lxc/lxc_driver.c | 3 +++ src/openvz/openvz_driver.c | 3 +++ src/qemu/qemu_driver.c | 3 +++ src/storage/storage_driver.c | 3 +++ src/test/test_driver.c | 3 +++ src/uml/uml_driver.c | 3 +++ src/vmware/vmware_driver.c | 3 +++ src/vz/vz_driver.c | 3 +++ src/xen/xen_driver.c | 3 +++ src/xenapi/xenapi_driver.c | 3 +++ 13 files changed, 39 insertions(+)
-- 2.7.4
-- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list

On 11.11.2016 10:17, Sławek Kapłoński wrote:
As https://bugzilla.redhat.com/show_bug.cgi?id=818064 is closed and new-line char is now forbiden in name of network, this patch forbids it also in names of domains and storage pools.
Sławek Kapłoński (2): Forbid new-line char in name of new domain Forbid new-line char in name of new storagepool
src/bhyve/bhyve_driver.c | 3 +++ src/esx/esx_driver.c | 3 +++ src/libxl/libxl_driver.c | 3 +++ src/lxc/lxc_driver.c | 3 +++ src/openvz/openvz_driver.c | 3 +++ src/qemu/qemu_driver.c | 3 +++ src/storage/storage_driver.c | 3 +++ src/test/test_driver.c | 3 +++ src/uml/uml_driver.c | 3 +++ src/vmware/vmware_driver.c | 3 +++ src/vz/vz_driver.c | 3 +++ src/xen/xen_driver.c | 3 +++ src/xenapi/xenapi_driver.c | 3 +++ 13 files changed, 39 insertions(+)
Fixed the problem in 1/2. ACKed and pushed. Michal

Hello, Thanks a lot. I have no idea how I not checked it. I compiled it for sure (but maybe not after this one change :/) -- Best regards / Pozdrawiam Sławek Kapłoński slawek@kaplonski.pl On Tue, 22 Nov 2016, Michal Privoznik wrote:
On 11.11.2016 10:17, Sławek Kapłoński wrote:
As https://bugzilla.redhat.com/show_bug.cgi?id=818064 is closed and new-line char is now forbiden in name of network, this patch forbids it also in names of domains and storage pools.
Sławek Kapłoński (2): Forbid new-line char in name of new domain Forbid new-line char in name of new storagepool
src/bhyve/bhyve_driver.c | 3 +++ src/esx/esx_driver.c | 3 +++ src/libxl/libxl_driver.c | 3 +++ src/lxc/lxc_driver.c | 3 +++ src/openvz/openvz_driver.c | 3 +++ src/qemu/qemu_driver.c | 3 +++ src/storage/storage_driver.c | 3 +++ src/test/test_driver.c | 3 +++ src/uml/uml_driver.c | 3 +++ src/vmware/vmware_driver.c | 3 +++ src/vz/vz_driver.c | 3 +++ src/xen/xen_driver.c | 3 +++ src/xenapi/xenapi_driver.c | 3 +++ 13 files changed, 39 insertions(+)
Fixed the problem in 1/2. ACKed and pushed.
Michal
-- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list
participants (2)
-
Michal Privoznik
-
Sławek Kapłoński