From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:55122) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bmHYO-0000n4-6G for qemu-devel@nongnu.org; Tue, 20 Sep 2016 05:41:28 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1bmHYL-0003wu-9E for qemu-devel@nongnu.org; Tue, 20 Sep 2016 05:41:27 -0400 Received: from mx1.redhat.com ([209.132.183.28]:42558) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bmHYL-0003wF-2Y for qemu-devel@nongnu.org; Tue, 20 Sep 2016 05:41:25 -0400 Received: from int-mx11.intmail.prod.int.phx2.redhat.com (int-mx11.intmail.prod.int.phx2.redhat.com [10.5.11.24]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 907FD4E358 for ; Tue, 20 Sep 2016 09:41:24 +0000 (UTC) Date: Tue, 20 Sep 2016 11:37:59 +0200 From: =?UTF-8?B?VG9tw6HFoSBHb2xlbWJpb3Zza8O9?= Message-ID: <20160920113759.23a1ee06@fiorina> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable Subject: [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: Paolo Bonzini , qemu-devel@nongnu.org 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=C3=A1=C5=A1 Golembiovsk=C3=BD --- 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); } =20 + if (dev_offset >=3D fd_size) { + error_report("Offset (%lu) has to be smaller than the image size (= %lu)", + dev_offset, fd_size); + exit(EXIT_FAILURE); + } + fd_size -=3D dev_offset; + if (partition !=3D -1) { ret =3D find_partition(blk, partition, &dev_offset, &fd_size); if (ret < 0) { --=20 2.9.3