]> git.ipfire.org Git - thirdparty/qemu.git/commitdiff
qemu-img: fix division by zero in bench_cb() for zero-sized images
authorDenis Rastyogin <gerben@altlinux.org>
Tue, 18 Mar 2025 10:19:00 +0000 (13:19 +0300)
committerKevin Wolf <kwolf@redhat.com>
Tue, 8 Apr 2025 10:13:17 +0000 (12:13 +0200)
This error was discovered by fuzzing qemu-img.

This commit fixes a division by zero error in the bench_cb() function
that occurs when using the bench command with a zero-sized image.

The issue arises because b->image_size can be zero, leading to a
division by zero in the modulo operation (b->offset %= b->image_size).
This patch adds a check for b->image_size == 0 and resets b->offset
to 0 in such cases, preventing the error.

Signed-off-by: Denis Rastyogin <gerben@altlinux.org>
Message-ID: <20250318101933.255617-1-gerben@altlinux.org>
Reviewed-by: Kevin Wolf <kwolf@redhat.com>
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
qemu-img.c

index 89c93c1eb588b9d8aed9bdc3126636137a3fbfd2..2044c22a4c7d30b69fcb8e6346c176f8fe787550 100644 (file)
@@ -4488,7 +4488,11 @@ static void bench_cb(void *opaque, int ret)
          */
         b->in_flight++;
         b->offset += b->step;
-        b->offset %= b->image_size;
+        if (b->image_size == 0) {
+            b->offset = 0;
+        } else {
+            b->offset %= b->image_size;
+        }
         if (b->write) {
             acb = blk_aio_pwritev(b->blk, offset, b->qiov, 0, bench_cb, b);
         } else {