Received: from eggs.gnu.org ([2001:4830:134:3::10]:34479) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bsYU0-0004MX-6Z for qemu-devel@nongnu.org; Fri, 07 Oct 2016 12:58:53 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1bsYTy-0008Ns-Ah for qemu-devel@nongnu.org; Fri, 07 Oct 2016 12:58:51 -0400 Received: from mx1.redhat.com ([209.132.183.28]:39842) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bsYTy-0008No-4f for qemu-devel@nongnu.org; Fri, 07 Oct 2016 12:58:50 -0400 Received: from int-mx10.intmail.prod.int.phx2.redhat.com (int-mx10.intmail.prod.int.phx2.redhat.com [10.5.11.23]) (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 911704DD60 for ; Fri, 7 Oct 2016 16:58:49 +0000 (UTC) From: Paolo Bonzini Date: Fri, 7 Oct 2016 18:57:50 +0200 Message-Id: <1475859483-32234-27-git-send-email-pbonzini@redhat.com> In-Reply-To: <1475859483-32234-1-git-send-email-pbonzini@redhat.com> References: <1475859483-32234-1-git-send-email-pbonzini@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable Subject: [Qemu-devel] [PULL 26/39] qemu-nbd: Shrink image size by specified offset List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org Cc: =?UTF-8?q?Tom=C3=A1=C5=A1=20Golembiovsk=C3=BD?= From: Tom=C3=A1=C5=A1 Golembiovsk=C3=BD 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 Message-Id: <8a31654cb182932db78b95aae1e904fc2bd1c465.1475698895.git.tgol= embi@redhat.com> Reviewed-by: Eric Blake Signed-off-by: Paolo Bonzini --- 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); } =20 + if (dev_offset >=3D fd_size) { + error_report("Offset (%lld) has to be smaller than the image siz= e " + "(%lld)", + (long long int)dev_offset, (long long int)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.7.4