From: Vladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com>
To: qemu-devel@nongnu.org
Cc: den@openvz.org, vsementsov@virtuozzo.com, kwolf@redhat.com,
mreitz@redhat.com
Subject: [Qemu-devel] [PATCH 1/2] hbitmap: add 'pos < size' asserts
Date: Tue, 14 Jun 2016 20:08:12 +0300 [thread overview]
Message-ID: <1465924093-76875-2-git-send-email-vsementsov@virtuozzo.com> (raw)
In-Reply-To: <1465924093-76875-1-git-send-email-vsementsov@virtuozzo.com>
For now, fail in hbitmap_set on start + count > size will come from
hbitmap_set
hb_count_between
hbitmap_iter_init
assert(pos < hb->size)
This patch adds such checks to set/get/reset functions of hbitmap.
Signed-off-by: Vladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com>
---
util/hbitmap.c | 3 +++
1 file changed, 3 insertions(+)
diff --git a/util/hbitmap.c b/util/hbitmap.c
index 7121b11..99fd2ba 100644
--- a/util/hbitmap.c
+++ b/util/hbitmap.c
@@ -269,6 +269,7 @@ void hbitmap_set(HBitmap *hb, uint64_t start, uint64_t count)
start >>= hb->granularity;
last >>= hb->granularity;
count = last - start + 1;
+ assert(last < hb->size);
hb->count += count - hb_count_between(hb, start, last);
hb_set_between(hb, HBITMAP_LEVELS - 1, start, last);
@@ -348,6 +349,7 @@ void hbitmap_reset(HBitmap *hb, uint64_t start, uint64_t count)
start >>= hb->granularity;
last >>= hb->granularity;
+ assert(last < hb->size);
hb->count -= hb_count_between(hb, start, last);
hb_reset_between(hb, HBITMAP_LEVELS - 1, start, last);
@@ -371,6 +373,7 @@ bool hbitmap_get(const HBitmap *hb, uint64_t item)
/* Compute position and bit in the last layer. */
uint64_t pos = item >> hb->granularity;
unsigned long bit = 1UL << (pos & (BITS_PER_LONG - 1));
+ assert(pos < hb->size);
return (hb->levels[HBITMAP_LEVELS - 1][pos >> BITS_PER_LEVEL] & bit) != 0;
}
--
1.8.3.1
next prev parent reply other threads:[~2016-06-14 17:08 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-06-14 17:08 [Qemu-devel] [PATCH v2 0/2] block: fix libvirt snapshot with existing bitmaps Vladimir Sementsov-Ogievskiy
2016-06-14 17:08 ` Vladimir Sementsov-Ogievskiy [this message]
2016-06-14 17:08 ` [Qemu-devel] [PATCH 2/2] " Vladimir Sementsov-Ogievskiy
2016-06-14 21:33 ` Eric Blake
2016-06-15 13:08 ` Vladimir Sementsov-Ogievskiy
2016-06-15 15:29 ` Max Reitz
2016-06-14 18:09 ` [Qemu-devel] [PATCH v2 0/2] " Max Reitz
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1465924093-76875-2-git-send-email-vsementsov@virtuozzo.com \
--to=vsementsov@virtuozzo.com \
--cc=den@openvz.org \
--cc=kwolf@redhat.com \
--cc=mreitz@redhat.com \
--cc=qemu-devel@nongnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).