Commit 728d945ea0 for qemu.org
commit 728d945ea07d5961733059604dcc608ec132dde6
Author: Fabiano Rosas <farosas@suse.de>
Date: Tue Aug 18 15:24:39 2026 -0300
migration: Check more vmstate flags
Add more checks for vmstate flags constraints.
Acked-by: Peter Xu <peterx@redhat.com>
Signed-off-by: Fabiano Rosas <farosas@suse.de>
diff --git a/migration/savevm.c b/migration/savevm.c
index ba705c941a..5b0e89ca7c 100644
--- a/migration/savevm.c
+++ b/migration/savevm.c
@@ -893,6 +893,25 @@ static void vmstate_check(const VMStateDescription *vmsd)
assert(field->flags & VMS_ARRAY_OF_POINTER);
}
+ /*
+ * The VMS*ARRAY flags and VMS_VBUFFER affect allocation,
+ * they must have the proper fields set and no other
+ * vmstate types can set those fields, otherwise it won't
+ * be picked-up due to the missing flag.
+ */
+
+ if (field->flags & (VMS_ARRAY | VMS_VARRAY)) {
+ assert(field->num > 0 || field->num_indirect.size != 0);
+ } else {
+ assert(field->num == 0 && field->num_indirect.size == 0);
+ }
+
+ if (field->flags & VMS_VBUFFER) {
+ assert(field->size_indirect.size != 0);
+ } else {
+ assert(field->size_indirect.size == 0);
+ }
+
if (field->flags & (VMS_STRUCT | VMS_VSTRUCT)) {
/* Recurse to sub structures */
vmstate_check(field->vmsd);