From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:44393) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1XhPEE-0006Ud-6P for qemu-devel@nongnu.org; Thu, 23 Oct 2014 16:43:31 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1XhPE8-0002cu-Ub for qemu-devel@nongnu.org; Thu, 23 Oct 2014 16:43:26 -0400 Received: from mx1.redhat.com ([209.132.183.28]:12538) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1XhPE8-0002cS-OC for qemu-devel@nongnu.org; Thu, 23 Oct 2014 16:43:20 -0400 Received: from int-mx09.intmail.prod.int.phx2.redhat.com (int-mx09.intmail.prod.int.phx2.redhat.com [10.5.11.22]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id s9NKhKWj015764 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=FAIL) for ; Thu, 23 Oct 2014 16:43:20 -0400 From: Kevin Wolf Date: Thu, 23 Oct 2014 22:42:34 +0200 Message-Id: <1414096959-14682-28-git-send-email-kwolf@redhat.com> In-Reply-To: <1414096959-14682-1-git-send-email-kwolf@redhat.com> References: <1414096959-14682-1-git-send-email-kwolf@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable Subject: [Qemu-devel] [PULL 27/32] qemu-io: Respect early image end for map List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org Cc: kwolf@redhat.com From: Max Reitz bdrv_is_allocated() may report zero clusters which most probably means the image (file) is shorter than expected. Respect this case in order to avoid an infinite loop. Signed-off-by: Max Reitz Reviewed-by: Eric Blake Reviewed-by: Beno=C3=AEt Canet Reviewed-by: Kevin Wolf Signed-off-by: Kevin Wolf --- qemu-io-cmds.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/qemu-io-cmds.c b/qemu-io-cmds.c index b224ede..d94fb1e 100644 --- a/qemu-io-cmds.c +++ b/qemu-io-cmds.c @@ -1900,7 +1900,7 @@ static int map_is_allocated(BlockDriverState *bs, i= nt64_t sector_num, =20 num_checked =3D MIN(nb_sectors, INT_MAX); ret =3D bdrv_is_allocated(bs, sector_num, num_checked, &num); - if (ret =3D=3D firstret) { + if (ret =3D=3D firstret && num) { *pnum +=3D num; } else { break; @@ -1927,6 +1927,9 @@ static int map_f(BlockDriverState *bs, int argc, ch= ar **argv) if (ret < 0) { error_report("Failed to get allocation status: %s", strerror= (-ret)); return 0; + } else if (!num) { + error_report("Unexpected end of image"); + return 0; } =20 retstr =3D ret ? " allocated" : "not allocated"; --=20 1.8.3.1