render / rpms / qemu

Forked from rpms/qemu 4 months ago
Clone

Blame 0001-block-blkio-Don-t-assume-size_t-is-64-bit.patch

93330a
From 02055de1ff1b15c7c12bff0457bae67c3db97f0a Mon Sep 17 00:00:00 2001
93330a
From: "Richard W.M. Jones" <rjones@redhat.com>
93330a
Date: Mon, 29 Jan 2024 18:20:46 +0000
93330a
Subject: [PATCH] block/blkio: Don't assume size_t is 64 bit
93330a
MIME-Version: 1.0
93330a
Content-Type: text/plain; charset=UTF-8
93330a
Content-Transfer-Encoding: 8bit
93330a
93330a
With GCC 14 the code failed to compile on i686 (and was wrong for any
93330a
version of GCC):
93330a
93330a
../block/blkio.c: In function ‘blkio_file_open’:
93330a
../block/blkio.c:857:28: error: passing argument 3 of ‘blkio_get_uint64’ from incompatible pointer type [-Wincompatible-pointer-types]
93330a
  857 |                            &s->mem_region_alignment);
93330a
      |                            ^~~~~~~~~~~~~~~~~~~~~~~~
93330a
      |                            |
93330a
      |                            size_t * {aka unsigned int *}
93330a
In file included from ../block/blkio.c:12:
93330a
/usr/include/blkio.h:49:67: note: expected ‘uint64_t *’ {aka ‘long long unsigned int *’} but argument is of type ‘size_t *’ {aka ‘unsigned int *’}
93330a
   49 | int blkio_get_uint64(struct blkio *b, const char *name, uint64_t *value);
93330a
      |                                                         ~~~~~~~~~~^~~~~
93330a
93330a
Signed-off-by: Richard W.M. Jones <rjones@redhat.com>
93330a
---
93330a
 block/blkio.c | 12 +++++++++++-
93330a
 1 file changed, 11 insertions(+), 1 deletion(-)
93330a
93330a
diff --git a/block/blkio.c b/block/blkio.c
93330a
index 0a0a6c0f5fd..52d78935147 100644
93330a
--- a/block/blkio.c
93330a
+++ b/block/blkio.c
93330a
@@ -794,6 +794,7 @@ static int blkio_file_open(BlockDriverState *bs, QDict *options, int flags,
93330a
     const char *blkio_driver = bs->drv->protocol_name;
93330a
     BDRVBlkioState *s = bs->opaque;
93330a
     int ret;
93330a
+    uint64_t val;
93330a
 
93330a
     ret = blkio_create(blkio_driver, &s->blkio);
93330a
     if (ret < 0) {
93330a
@@ -854,7 +855,7 @@ static int blkio_file_open(BlockDriverState *bs, QDict *options, int flags,
93330a
 
93330a
     ret = blkio_get_uint64(s->blkio,
93330a
                            "mem-region-alignment",
93330a
-                           &s->mem_region_alignment);
93330a
+                           &val;;
93330a
     if (ret < 0) {
93330a
         error_setg_errno(errp, -ret,
93330a
                          "failed to get mem-region-alignment: %s",
93330a
@@ -862,6 +863,15 @@ static int blkio_file_open(BlockDriverState *bs, QDict *options, int flags,
93330a
         blkio_destroy(&s->blkio);
93330a
         return ret;
93330a
     }
93330a
+#if HOST_LONG_BITS == 32
93330a
+    if (val > SIZE_MAX) {
93330a
+        error_setg_errno(errp, ERANGE,
93330a
+                         "mem-region-alignment too large for size_t");
93330a
+        blkio_destroy(&s->blkio);
93330a
+        return -ERANGE;
93330a
+    }
93330a
+#endif
93330a
+    s->mem_region_alignment = (size_t)val;
93330a
 
93330a
     ret = blkio_get_bool(s->blkio,
93330a
                          "may-pin-mem-regions",
93330a
-- 
93330a
2.43.0
93330a