* [Qemu-devel] [PATCH v2] qemu-nbd: Shrink image size by specified offset
@ 2016-10-05 21:40 Tomáš Golembiovský
2016-10-05 21:51 ` Eric Blake
2016-10-06 10:46 ` Paolo Bonzini
0 siblings, 2 replies; 3+ messages in thread
From: Tomáš Golembiovský @ 2016-10-05 21:40 UTC (permalink / raw)
To: Paolo Bonzini, qemu-devel; +Cc: Tomáš Golembiovský
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>
---
qemu-nbd.c | 8 ++++++++
1 file changed, 8 insertions(+)
diff --git a/qemu-nbd.c b/qemu-nbd.c
index 99297a5..705b95e 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) {
--
2.10.0
v1 -> v2:
- cast off_t variables to type with known formatting flag
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [Qemu-devel] [PATCH v2] qemu-nbd: Shrink image size by specified offset
2016-10-05 21:40 [Qemu-devel] [PATCH v2] qemu-nbd: Shrink image size by specified offset Tomáš Golembiovský
@ 2016-10-05 21:51 ` Eric Blake
2016-10-06 10:46 ` Paolo Bonzini
1 sibling, 0 replies; 3+ messages in thread
From: Eric Blake @ 2016-10-05 21:51 UTC (permalink / raw)
To: Tomáš Golembiovský, Paolo Bonzini, qemu-devel
[-- Attachment #1: Type: text/plain, Size: 1178 bytes --]
On 10/05/2016 04:40 PM, Tomáš Golembiovský wrote:
> 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>
> ---
> qemu-nbd.c | 8 ++++++++
> 1 file changed, 8 insertions(+)
Reviewed-by: Eric Blake <eblake@redhat.com>
>
> diff --git a/qemu-nbd.c b/qemu-nbd.c
> index 99297a5..705b95e 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) {
>
--
Eric Blake eblake redhat com +1-919-301-3266
Libvirt virtualization library http://libvirt.org
[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 604 bytes --]
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [Qemu-devel] [PATCH v2] qemu-nbd: Shrink image size by specified offset
2016-10-05 21:40 [Qemu-devel] [PATCH v2] qemu-nbd: Shrink image size by specified offset Tomáš Golembiovský
2016-10-05 21:51 ` Eric Blake
@ 2016-10-06 10:46 ` Paolo Bonzini
1 sibling, 0 replies; 3+ messages in thread
From: Paolo Bonzini @ 2016-10-06 10:46 UTC (permalink / raw)
To: Tomáš Golembiovský, qemu-devel
On 05/10/2016 23:40, Tomáš Golembiovský wrote:
> 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>
Queued, thanks.
Paolo
> ---
> qemu-nbd.c | 8 ++++++++
> 1 file changed, 8 insertions(+)
>
> diff --git a/qemu-nbd.c b/qemu-nbd.c
> index 99297a5..705b95e 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) {
>
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2016-10-06 10:46 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2016-10-05 21:40 [Qemu-devel] [PATCH v2] qemu-nbd: Shrink image size by specified offset Tomáš Golembiovský
2016-10-05 21:51 ` Eric Blake
2016-10-06 10:46 ` Paolo Bonzini
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).