From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:49245) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bmIty-0000oM-UR for qemu-devel@nongnu.org; Tue, 20 Sep 2016 07:07:56 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1bmItt-0006d7-QP for qemu-devel@nongnu.org; Tue, 20 Sep 2016 07:07:49 -0400 Received: from mail-yw0-x243.google.com ([2607:f8b0:4002:c05::243]:34919) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bmItt-0006cg-LR for qemu-devel@nongnu.org; Tue, 20 Sep 2016 07:07:45 -0400 Received: by mail-yw0-x243.google.com with SMTP id u82so566146ywc.2 for ; Tue, 20 Sep 2016 04:07:45 -0700 (PDT) Sender: Paolo Bonzini References: <20160920113759.23a1ee06@fiorina> From: Paolo Bonzini Message-ID: Date: Tue, 20 Sep 2016 11:59:22 +0200 MIME-Version: 1.0 In-Reply-To: <20160920113759.23a1ee06@fiorina> Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit Subject: Re: [Qemu-devel] [PATCH 1/2] qemu-nbd: Shrink image size by specified offset List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: =?UTF-8?B?VG9tw6HFoSBHb2xlbWJpb3Zza8O9?= , qemu-devel@nongnu.org On 20/09/2016 11:37, 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ý > --- > 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) { > Reviewed-by: Paolo Bonzini