aboutsummaryrefslogtreecommitdiff
path: root/qemu-nbd.c
diff options
context:
space:
mode:
authorTomáš Golembiovský <tgolembi@redhat.com>2016-10-05 23:40:20 +0200
committerPaolo Bonzini <pbonzini@redhat.com>2016-10-06 18:04:13 +0200
commite424b6550f486b2a9ab32b13c3824021199bac54 (patch)
tree3cd45550b2276e87a281ffe6adbc1f2b4f535dd6 /qemu-nbd.c
parentfbe7e3327a8cfa1b08664c2cda7a0a341cf0530a (diff)
qemu-nbd: Shrink image size by specified offset
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>
Diffstat (limited to 'qemu-nbd.c')
-rw-r--r--qemu-nbd.c8
1 files changed, 8 insertions, 0 deletions
diff --git a/qemu-nbd.c b/qemu-nbd.c
index 99297a556f..705b95ec29 100644
--- a/qemu-nbd.c
+++ b/qemu-nbd.c
@@ -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) {