aboutsummaryrefslogtreecommitdiff
path: root/util
diff options
context:
space:
mode:
authorVladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com>2020-02-05 14:20:32 +0300
committerJohn Snow <jsnow@redhat.com>2020-03-18 14:03:46 -0400
commit6a150995d486013221361cddb5ae6189afb0cef5 (patch)
tree65df18eccb63b7cfb3ab6cb40809c90303460116 /util
parent9bda600b0833821685e23068e50be5134dc0ab05 (diff)
downloadqemu-6a150995d486013221361cddb5ae6189afb0cef5.zip
qemu-6a150995d486013221361cddb5ae6189afb0cef5.tar.gz
qemu-6a150995d486013221361cddb5ae6189afb0cef5.tar.bz2
hbitmap: assert that we don't create bitmap larger than INT64_MAX
We have APIs which returns signed int64_t, to be able to return error. Therefore we can't handle bitmaps with absolute size larger than (INT64_MAX+1). Still, keep maximum to be INT64_MAX which is a bit safer. Note, that bitmaps are used to represent disk images, which can't exceed INT64_MAX anyway. Signed-off-by: Vladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com> Reviewed-by: Max Reitz <mreitz@redhat.com> Reviewed-by: Eric Blake <eblake@redhat.com> Reviewed-by: John Snow <jsnow@redhat.com> Message-id: 20200205112041.6003-2-vsementsov@virtuozzo.com Signed-off-by: John Snow <jsnow@redhat.com>
Diffstat (limited to 'util')
-rw-r--r--util/hbitmap.c2
1 files changed, 2 insertions, 0 deletions
diff --git a/util/hbitmap.c b/util/hbitmap.c
index 242c6e5..7f9b3e0 100644
--- a/util/hbitmap.c
+++ b/util/hbitmap.c
@@ -716,6 +716,7 @@ HBitmap *hbitmap_alloc(uint64_t size, int granularity)
HBitmap *hb = g_new0(struct HBitmap, 1);
unsigned i;
+ assert(size <= INT64_MAX);
hb->orig_size = size;
assert(granularity >= 0 && granularity < 64);
@@ -746,6 +747,7 @@ void hbitmap_truncate(HBitmap *hb, uint64_t size)
uint64_t num_elements = size;
uint64_t old;
+ assert(size <= INT64_MAX);
hb->orig_size = size;
/* Size comes in as logical elements, adjust for granularity. */