diff mbox series

[v2,1/5] hbitmap: handle set/reset with zero length

Message ID 20191011090711.19940-2-vsementsov@virtuozzo.com
State New
Headers show
Series active-mirror: support unaligned guest operations | expand

Commit Message

Vladimir Sementsov-Ogievskiy Oct. 11, 2019, 9:07 a.m. UTC
Passing zero length to these functions leads to unpredicted results.
Zero-length set/reset may occur in active-mirror, on zero-length write
(which is unlikely, but not guaranteed to never happen).

Let's just do nothing on zero-length request.

Signed-off-by: Vladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com>
---
 util/hbitmap.c | 8 ++++++++
 1 file changed, 8 insertions(+)

Comments

Max Reitz Oct. 18, 2019, 3:29 p.m. UTC | #1
On 11.10.19 11:07, Vladimir Sementsov-Ogievskiy wrote:
> Passing zero length to these functions leads to unpredicted results.
> Zero-length set/reset may occur in active-mirror, on zero-length write
> (which is unlikely, but not guaranteed to never happen).
> 
> Let's just do nothing on zero-length request.
> 
> Signed-off-by: Vladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com>
> ---
>  util/hbitmap.c | 8 ++++++++
>  1 file changed, 8 insertions(+)

Reviewed-by: Max Reitz <mreitz@redhat.com>
diff mbox series

Patch

diff --git a/util/hbitmap.c b/util/hbitmap.c
index fd44c897ab..86b0231046 100644
--- a/util/hbitmap.c
+++ b/util/hbitmap.c
@@ -387,6 +387,10 @@  void hbitmap_set(HBitmap *hb, uint64_t start, uint64_t count)
     uint64_t first, n;
     uint64_t last = start + count - 1;
 
+    if (count == 0) {
+        return;
+    }
+
     trace_hbitmap_set(hb, start, count,
                       start >> hb->granularity, last >> hb->granularity);
 
@@ -477,6 +481,10 @@  void hbitmap_reset(HBitmap *hb, uint64_t start, uint64_t count)
     uint64_t first;
     uint64_t last = start + count - 1;
 
+    if (count == 0) {
+        return;
+    }
+
     trace_hbitmap_reset(hb, start, count,
                         start >> hb->granularity, last >> hb->granularity);