qemu-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Qemu-devel] [PATCH 1/2] qemu-nbd: Shrink image size by specified offset


From: Tomáš Golembiovský
Subject: [Qemu-devel] [PATCH 1/2] qemu-nbd: Shrink image size by specified offset
Date: Tue, 20 Sep 2016 11:37:59 +0200

When --offset is set the apparent device size has to be adjusted
accordingly. Otherwise client may request read/write beyond the file end
which would fail.

Signed-off-by: Tomáš Golembiovský <address@hidden>
---
 qemu-nbd.c | 7 +++++++
 1 file changed, 7 insertions(+)

diff --git a/qemu-nbd.c b/qemu-nbd.c
index 99297a5..629bce1 100644
--- a/qemu-nbd.c
+++ b/qemu-nbd.c
@@ -901,6 +901,13 @@ int main(int argc, char **argv)
         exit(EXIT_FAILURE);
     }
 
+    if (dev_offset >= fd_size) {
+        error_report("Offset (%lu) has to be smaller than the image size 
(%lu)",
+                     dev_offset, fd_size);
+        exit(EXIT_FAILURE);
+    }
+    fd_size -= dev_offset;
+
     if (partition != -1) {
         ret = find_partition(blk, partition, &dev_offset, &fd_size);
         if (ret < 0) {
-- 
2.9.3





reply via email to

[Prev in Thread] Current Thread [Next in Thread]