Enum variable of type qemuMigrationCapability is checked for zero in
src/qemu/qemu_migration_params.c:729.

"if (item->optional) { ..."

Actualy, QEMU_MIGRATION_CAP_XBZRLE enum constant has value 0.
Thus, all uninitialized .optinnal fields of the static array
qemuMigrationParamsFlagMap[] will be implicitly initialized with
value 0 (QEMU_MIGRATION_CAP_XBZRLE).
To my opinion, introducing a separate enum for optional capabilities,
would be a better solution.

Found by Linux Verification Center (linuxtesting.org) with SVACE.

Signed-off-by: Dmitry Frolov <fro...@swemel.ru>
---
 src/qemu/qemu_migration_params.c | 16 +++++++++++-----
 src/qemu/qemu_migration_params.h | 12 ++++++++++--
 2 files changed, 21 insertions(+), 7 deletions(-)

diff --git a/src/qemu/qemu_migration_params.c b/src/qemu/qemu_migration_params.c
index c10660d6f2..23c463dbbb 100644
--- a/src/qemu/qemu_migration_params.c
+++ b/src/qemu/qemu_migration_params.c
@@ -104,6 +104,11 @@ VIR_ENUM_IMPL(qemuMigrationCapability,
               "dirty-bitmaps",
               "return-path",
               "zero-copy-send",
+);
+
+VIR_ENUM_IMPL(qemuMigrationOptCap,
+              QEMU_MIGRATION_OPTCAP_LAST,
+              "none",
               "postcopy-preempt",
               "switchover-ack",
 );
@@ -152,7 +157,7 @@ struct _qemuMigrationParamsFlagMapItem {
     /* An optional capability to set in addition to @cap in case it is
      * supported. Depending on @part either one or both sides of migration
      * has to support the optional capability to be enabled. */
-    qemuMigrationCapability optional;
+    qemuMigrationOptCap optional;
     /* Bit-wise OR of qemuMigrationParty. Determines whether the capability has
      * to be enabled on the source, on the destination, or on both sides of
      * migration. */
@@ -200,7 +205,7 @@ static const qemuMigrationParamsFlagMapItem 
qemuMigrationParamsFlagMap[] = {
     {.match = QEMU_MIGRATION_FLAG_REQUIRED,
      .flag = VIR_MIGRATE_POSTCOPY,
      .cap = QEMU_MIGRATION_CAP_POSTCOPY,
-     .optional = QEMU_MIGRATION_CAP_POSTCOPY_PREEMPT,
+     .optional = QEMU_MIGRATION_OPTCAP_POSTCOPY_PREEMPT,
      .party = QEMU_MIGRATION_SOURCE | QEMU_MIGRATION_DESTINATION},
 
     {.match = QEMU_MIGRATION_FLAG_REQUIRED,
@@ -211,7 +216,7 @@ static const qemuMigrationParamsFlagMapItem 
qemuMigrationParamsFlagMap[] = {
     {.match = QEMU_MIGRATION_FLAG_FORBIDDEN,
      .flag = VIR_MIGRATE_TUNNELLED,
      .cap = QEMU_MIGRATION_CAP_RETURN_PATH,
-     .optional = QEMU_MIGRATION_CAP_SWITCHOVER_ACK,
+     .optional = QEMU_MIGRATION_OPTCAP_SWITCHOVER_ACK,
      .party = QEMU_MIGRATION_SOURCE | QEMU_MIGRATION_DESTINATION},
 
     {.match = QEMU_MIGRATION_FLAG_REQUIRED,
@@ -725,8 +730,9 @@ qemuMigrationParamsFromFlags(virTypedParameterPtr params,
                       qemuMigrationCapabilityTypeToString(item->cap));
             ignore_value(virBitmapSetBit(migParams->caps, item->cap));
 
-            if (item->optional) {
-                qemuMigrationCapability opt = item->optional;
+            if (item->optional > QEMU_MIGRATION_OPTCAP_NONE &&
+                item->optional < QEMU_MIGRATION_OPTCAP_LAST) {
+                qemuMigrationOptCap opt = item->optional;
                 ignore_value(virBitmapSetBit(migParams->optional, opt));
                 if (item->party != party)
                     ignore_value(virBitmapSetBit(migParams->remoteOptional, 
opt));
diff --git a/src/qemu/qemu_migration_params.h b/src/qemu/qemu_migration_params.h
index 17fc63f527..3246b8487e 100644
--- a/src/qemu/qemu_migration_params.h
+++ b/src/qemu/qemu_migration_params.h
@@ -40,13 +40,21 @@ typedef enum {
     QEMU_MIGRATION_CAP_BLOCK_DIRTY_BITMAPS,
     QEMU_MIGRATION_CAP_RETURN_PATH,
     QEMU_MIGRATION_CAP_ZERO_COPY_SEND,
-    QEMU_MIGRATION_CAP_POSTCOPY_PREEMPT,
-    QEMU_MIGRATION_CAP_SWITCHOVER_ACK,
 
     QEMU_MIGRATION_CAP_LAST
 } qemuMigrationCapability;
 VIR_ENUM_DECL(qemuMigrationCapability);
 
+typedef enum {
+    QEMU_MIGRATION_OPTCAP_NONE,
+    QEMU_MIGRATION_OPTCAP_POSTCOPY_PREEMPT,
+    QEMU_MIGRATION_OPTCAP_SWITCHOVER_ACK,
+
+    QEMU_MIGRATION_OPTCAP_LAST
+} qemuMigrationOptCap;
+VIR_ENUM_DECL(qemuMigrationOptCap);
+
+
 typedef enum {
     QEMU_MIGRATION_PARAM_COMPRESS_LEVEL,
     QEMU_MIGRATION_PARAM_COMPRESS_THREADS,
-- 
2.34.1

Reply via email to