From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:35186) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1XgvuA-0005ie-Lk for qemu-devel@nongnu.org; Wed, 22 Oct 2014 09:24:51 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Xgvu5-0007XT-Iv for qemu-devel@nongnu.org; Wed, 22 Oct 2014 09:24:46 -0400 Received: from mx1.redhat.com ([209.132.183.28]:15993) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Xgvu5-0007X9-9u for qemu-devel@nongnu.org; Wed, 22 Oct 2014 09:24:41 -0400 From: Max Reitz Date: Wed, 22 Oct 2014 15:24:30 +0200 Message-Id: <1413984271-15471-3-git-send-email-mreitz@redhat.com> In-Reply-To: <1413984271-15471-1-git-send-email-mreitz@redhat.com> References: <1413984271-15471-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 v2 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 --- 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