diff options
author | Philippe Mathieu-Daudé <philmd@redhat.com> | 2023-08-11 18:52:29 +0100 |
---|---|---|
committer | Kevin Wolf <kwolf@redhat.com> | 2023-09-08 17:03:09 +0200 |
commit | 3c2c599c79eea9cebd7280140a5901fe3734e94e (patch) | |
tree | fb47cc53bace6356f2350d9cd169bbdefe7952f3 | |
parent | 13d9f6dca08a38e9258b6328f3ad61bdb8e19619 (diff) | |
download | qemu-3c2c599c79eea9cebd7280140a5901fe3734e94e.zip qemu-3c2c599c79eea9cebd7280140a5901fe3734e94e.tar.gz qemu-3c2c599c79eea9cebd7280140a5901fe3734e94e.tar.bz2 |
block/vpc: Avoid dynamic stack allocation
Use autofree heap allocation instead of variable-length array on the
stack. Here we don't expect the bitmap size to be enormous, and
since we're about to read/write it to disk the overhead of the
allocation should be fine.
The codebase has very few VLAs, and if we can get rid of them all we
can make the compiler error on new additions. This is a defensive
measure against security bugs where an on-stack dynamic allocation
isn't correctly size-checked (e.g. CVE-2021-3527).
Signed-off-by: Philippe Mathieu-Daudé <philmd@redhat.com>
[PMM: expanded commit message]
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
Message-ID: <20230811175229.808139-1-peter.maydell@linaro.org>
Reviewed-by: Kevin Wolf <kwolf@redhat.com>
Reviewed-by: Francisco Iglesias <frasse.iglesias@gmail.com>
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
-rw-r--r-- | block/vpc.c | 4 |
1 files changed, 2 insertions, 2 deletions
diff --git a/block/vpc.c b/block/vpc.c index 3810a60..ceb87dd 100644 --- a/block/vpc.c +++ b/block/vpc.c @@ -510,7 +510,7 @@ get_image_offset(BlockDriverState *bs, uint64_t offset, bool write, int *err) miss sparse read optimization, but it's not a problem in terms of correctness. */ if (write && (s->last_bitmap_offset != bitmap_offset)) { - uint8_t bitmap[s->bitmap_size]; + g_autofree uint8_t *bitmap = g_malloc(s->bitmap_size); int r; s->last_bitmap_offset = bitmap_offset; @@ -558,7 +558,7 @@ alloc_block(BlockDriverState *bs, int64_t offset) int64_t bat_offset; uint32_t index, bat_value; int ret; - uint8_t bitmap[s->bitmap_size]; + g_autofree uint8_t *bitmap = g_malloc(s->bitmap_size); /* Check if sector_num is valid */ if ((offset < 0) || (offset > bs->total_sectors * BDRV_SECTOR_SIZE)) { |