From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:32838) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1XgxOq-0004Xb-N2 for qemu-devel@nongnu.org; Wed, 22 Oct 2014 11:00:41 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1XgxOk-0000Vv-Gm for qemu-devel@nongnu.org; Wed, 22 Oct 2014 11:00:32 -0400 Received: from mx1.redhat.com ([209.132.183.28]:25374) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1XgxOk-0000Vj-9C for qemu-devel@nongnu.org; Wed, 22 Oct 2014 11:00:26 -0400 From: Max Reitz Date: Wed, 22 Oct 2014 17:00:16 +0200 Message-Id: <1413990017-19213-3-git-send-email-mreitz@redhat.com> In-Reply-To: <1413990017-19213-1-git-send-email-mreitz@redhat.com> References: <1413990017-19213-1-git-send-email-mreitz@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable Subject: [Qemu-devel] [PATCH v3 2/3] 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: Kevin Wolf , =?UTF-8?q?Beno=C3=AEt=20Canet?= , Stefan Hajnoczi , 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 --- 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.9.3