]> git.proxmox.com Git - mirror_qemu.git/commitdiff
qemu-nbd: Shrink image size by specified offset
authorTomáš Golembiovský <tgolembi@redhat.com>
Wed, 5 Oct 2016 21:40:20 +0000 (23:40 +0200)
committerPaolo Bonzini <pbonzini@redhat.com>
Thu, 6 Oct 2016 16:04:13 +0000 (18:04 +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ý <tgolembi@redhat.com>
Message-Id: <8a31654cb182932db78b95aae1e904fc2bd1c465.1475698895.git.tgolembi@redhat.com>
Reviewed-by: Eric Blake <eblake@redhat.com>
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
qemu-nbd.c

index 99297a556fc8b8848b7be2b38267857e522ed6ff..705b95ec293d10ed3dc643b5743b1332c1645e60 100644 (file)
@@ -901,6 +901,14 @@ int main(int argc, char **argv)
         exit(EXIT_FAILURE);
     }
 
+    if (dev_offset >= fd_size) {
+        error_report("Offset (%lld) has to be smaller than the image size "
+                     "(%lld)",
+                     (long long int)dev_offset, (long long int)fd_size);
+        exit(EXIT_FAILURE);
+    }
+    fd_size -= dev_offset;
+
     if (partition != -1) {
         ret = find_partition(blk, partition, &dev_offset, &fd_size);
         if (ret < 0) {