Commit 319cd41f11 for qemu.org

commit 319cd41f110ada2cbb7dd17700893327a3cb925e
Author: Denis V. Lunev <den@openvz.org>
Date:   Tue Oct 6 19:07:36 2026 +0200

    migration: add QEMU_COUNTED_STRING_SIZE for counted string buffers

    A counted string carries its length in one byte, so the buffer that
    qemu_get_counted_string() fills must hold 256 bytes. The dirty bitmap
    load state spells that size as a bare 256 for both of its alias buffers.
    Name it next to the qemu_get_counted_string() prototype and use it there,
    in the length assert of qemu_put_counted_string() and in DBMLoadState.

    Suggested-by: Eric Blake <eblake@redhat.com>
    Signed-off-by: Denis V. Lunev <den@openvz.org>
    Cc: Peter Xu <peterx@redhat.com>
    Cc: Fabiano Rosas <farosas@suse.de>
    Cc: Eric Blake <eblake@redhat.com>
    Cc: Vladimir Sementsov-Ogievskiy <vsementsov@yandex-team.ru>
    Cc: qemu-stable@nongnu.org
    Message-ID: <20261006170738.453977-2-den@openvz.org>
    Reviewed-by: Eric Blake <eblake@redhat.com>
    Signed-off-by: Eric Blake <eblake@redhat.com>

diff --git a/include/migration/qemu-file-types.h b/include/migration/qemu-file-types.h
index adec5abc07..2a073bed29 100644
--- a/include/migration/qemu-file-types.h
+++ b/include/migration/qemu-file-types.h
@@ -163,7 +163,11 @@ static inline void qemu_get_sbe64s(QEMUFile *f, int64_t *pv)
     qemu_get_be64s(f, (uint64_t *)pv);
 }

-size_t coroutine_mixed_fn qemu_get_counted_string(QEMUFile *f, char buf[256]);
+/* Buffer size for a string whose length is sent as a single byte */
+#define QEMU_COUNTED_STRING_SIZE 256
+
+size_t coroutine_mixed_fn
+qemu_get_counted_string(QEMUFile *f, char buf[QEMU_COUNTED_STRING_SIZE]);

 void qemu_put_counted_string(QEMUFile *f, const char *name);

diff --git a/migration/block-dirty-bitmap.c b/migration/block-dirty-bitmap.c
index 1b8f39c12b..1386f43635 100644
--- a/migration/block-dirty-bitmap.c
+++ b/migration/block-dirty-bitmap.c
@@ -145,8 +145,8 @@ typedef struct LoadBitmapState {
 /* State of the dirty bitmap migration (DBM) during load process */
 typedef struct DBMLoadState {
     uint32_t flags;
-    char node_alias[256];
-    char bitmap_alias[256];
+    char node_alias[QEMU_COUNTED_STRING_SIZE];
+    char bitmap_alias[QEMU_COUNTED_STRING_SIZE];
     char bitmap_name[BDRV_BITMAP_MAX_NAME_SIZE + 1];
     BlockDriverState *bs;
     BdrvDirtyBitmap *bitmap;
diff --git a/migration/qemu-file.c b/migration/qemu-file.c
index 7735e61854..df3f96fb24 100644
--- a/migration/qemu-file.c
+++ b/migration/qemu-file.c
@@ -829,7 +829,8 @@ uint64_t qemu_get_be64(QEMUFile *f)
  *          else 0
  *          (Note a 0 length string will return 0 either way)
  */
-size_t coroutine_mixed_fn qemu_get_counted_string(QEMUFile *f, char buf[256])
+size_t coroutine_mixed_fn
+qemu_get_counted_string(QEMUFile *f, char buf[QEMU_COUNTED_STRING_SIZE])
 {
     size_t len = qemu_get_byte(f);
     size_t res = qemu_get_buffer(f, (uint8_t *)buf, len);
@@ -847,7 +848,7 @@ void qemu_put_counted_string(QEMUFile *f, const char *str)
 {
     size_t len = strlen(str);

-    assert(len < 256);
+    assert(len < QEMU_COUNTED_STRING_SIZE);
     qemu_put_byte(f, len);
     qemu_put_buffer(f, (const uint8_t *)str, len);
 }