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>
Fabiano Rosas committed
Aug 18, 2026 at 15:24 UTC
728d945ea07d5961733059604dcc608ec132dde6
1 file changed
+19
migration/savevm.c
+19
@@ -893,6 +893,25 @@ static void vmstate_check(const VMStateDescription *vmsd)
893
assert(field->flags & VMS_ARRAY_OF_POINTER);
894
}
895
896
+ /*
897
+ * The VMS*ARRAY flags and VMS_VBUFFER affect allocation,
898
+ * they must have the proper fields set and no other
899
+ * vmstate types can set those fields, otherwise it won't
900
+ * be picked-up due to the missing flag.
901
+ */
902
+
903
+ if (field->flags & (VMS_ARRAY | VMS_VARRAY)) {
904
+ assert(field->num > 0 || field->num_indirect.size != 0);
905
+ } else {
906
+ assert(field->num == 0 && field->num_indirect.size == 0);
907
+ }
908
+
909
+ if (field->flags & VMS_VBUFFER) {
910
+ assert(field->size_indirect.size != 0);
911
+ } else {
912
+ assert(field->size_indirect.size == 0);
913
+ }
914
+
915
if (field->flags & (VMS_STRUCT | VMS_VSTRUCT)) {
916
/* Recurse to sub structures */
917
vmstate_check(field->vmsd);