[PATCH 1/2] qemu: convert the flags type to unsigned long

Jiang Jiacheng posted 2 patches 3 years, 2 months ago
[PATCH 1/2] qemu: convert the flags type to unsigned long
Posted by Jiang Jiacheng 3 years, 2 months ago
The flags type is unsigend long but passed as unsigend int
when invoke 'qemuMigrationSrcNBDStorageCopy'. Modify it to
prevent data truncation.

Signed-off-by: Jiang Jiacheng <jiangjiacheng@huawei.com>
---
 src/qemu/qemu_migration.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/src/qemu/qemu_migration.c b/src/qemu/qemu_migration.c
index bba4e1dbf3..ba6c933885 100644
--- a/src/qemu/qemu_migration.c
+++ b/src/qemu/qemu_migration.c
@@ -1077,7 +1077,7 @@ qemuMigrationSrcNBDStorageCopyOne(virDomainObj *vm,
                                   bool mirror_shallow,
                                   const char *tlsAlias,
                                   const char *tlsHostname,
-                                  unsigned int flags)
+                                  unsigned long flags)
 {
     qemuDomainDiskPrivate *diskPriv = QEMU_DOMAIN_DISK_PRIVATE(disk);
     qemuBlockJobData *job = NULL;
@@ -1142,7 +1142,7 @@ qemuMigrationSrcNBDStorageCopy(virQEMUDriver *driver,
                                const char *tlsAlias,
                                const char *tlsHostname,
                                const char *nbdURI,
-                               unsigned int flags)
+                               unsigned long flags)
 {
     qemuDomainObjPrivate *priv = vm->privateData;
     int port;
-- 
2.33.0
Re: [PATCH 1/2] qemu: convert the flags type to unsigned long
Posted by Peter Krempa 3 years, 2 months ago
On Sat, Nov 19, 2022 at 17:31:27 +0800, Jiang Jiacheng wrote:
> The flags type is unsigend long but passed as unsigend int
> when invoke 'qemuMigrationSrcNBDStorageCopy'. Modify it to
> prevent data truncation.
> 
> Signed-off-by: Jiang Jiacheng <jiangjiacheng@huawei.com>
> ---
>  src/qemu/qemu_migration.c | 4 ++--
>  1 file changed, 2 insertions(+), 2 deletions(-)

Actually the use of 'unsigned long flags' in the migration APIs is a
historical mistake. While we can't remove that type from the function
prototype, internally the code MUST use 32 bit at most as 'unsigned
long' is not portable between 32 and 64 bit hosts.