diff options
author | Peter Maydell <peter.maydell@linaro.org> | 2024-10-08 17:47:08 +0100 |
---|---|---|
committer | Kevin Wolf <kwolf@redhat.com> | 2024-10-22 17:52:49 +0200 |
commit | 4d7c5f8335dad1aac9bf00704dab5409b9a9f4db (patch) | |
tree | 5db69d3e522966e980bc1182e27c5a84cf1bdf08 | |
parent | d60bd080e783107cb876a6f16561fe03f9dcbca7 (diff) | |
download | qemu-4d7c5f8335dad1aac9bf00704dab5409b9a9f4db.zip qemu-4d7c5f8335dad1aac9bf00704dab5409b9a9f4db.tar.gz qemu-4d7c5f8335dad1aac9bf00704dab5409b9a9f4db.tar.bz2 |
block/vdi.c: Make SECTOR_SIZE constant 64-bits
Make the VDI SECTOR_SIZE define be a 64-bit constant; this matches
how we define BDRV_SECTOR_SIZE. The benefit is that it means that we
don't need to carefully cast to 64-bits when doing operations like
"n_sectors * SECTOR_SIZE" to avoid doing a 32x32->32 multiply, which
might overflow, and which Coverity and other static analysers tend to
warn about.
The specific potential overflow Coverity is highlighting is the one
at the end of vdi_co_pwritev() where we write out n_sectors sectors
to the block map. This is very unlikely to actually overflow, since
the block map has 4 bytes per block and the maximum number of blocks
in the image must fit into a 32-bit integer. So this commit is not
fixing a real-world bug.
An inspection of all the places currently using SECTOR_SIZE in the
file shows none which care about the change in its type, except for
one call to error_setg() which needs the format string adjusting.
Resolves: Coverity CID 1508076
Suggested-by: Kevin Wolf <kwolf@redhat.com>
Message-ID: <20241008164708.2966400-5-peter.maydell@linaro.org>
Reviewed-by: Kevin Wolf <kwolf@redhat.com>
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
-rw-r--r-- | block/vdi.c | 4 |
1 files changed, 2 insertions, 2 deletions
diff --git a/block/vdi.c b/block/vdi.c index 149e15c..26f7638 100644 --- a/block/vdi.c +++ b/block/vdi.c @@ -87,7 +87,7 @@ /* Command line option for static images. */ #define BLOCK_OPT_STATIC "static" -#define SECTOR_SIZE 512 +#define SECTOR_SIZE 512ULL #define DEFAULT_CLUSTER_SIZE 1048576 /* Note: can't use 1 * MiB, because it's passed to stringify() */ @@ -442,7 +442,7 @@ static int vdi_open(BlockDriverState *bs, QDict *options, int flags, goto fail; } else if (header.sector_size != SECTOR_SIZE) { error_setg(errp, "unsupported VDI image (sector size %" PRIu32 - " is not %u)", header.sector_size, SECTOR_SIZE); + " is not %llu)", header.sector_size, SECTOR_SIZE); ret = -ENOTSUP; goto fail; } else if (header.block_size != DEFAULT_CLUSTER_SIZE) { |