From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:48557) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Xu0Na-0000eC-HE for qemu-devel@nongnu.org; Thu, 27 Nov 2014 09:49:15 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Xu0NV-0003aR-Fg for qemu-devel@nongnu.org; Thu, 27 Nov 2014 09:49:10 -0500 Received: from mx1.redhat.com ([209.132.183.28]:48855) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Xu0NV-0003aE-1D for qemu-devel@nongnu.org; Thu, 27 Nov 2014 09:49:05 -0500 From: Max Reitz Date: Thu, 27 Nov 2014 15:48:37 +0100 Message-Id: <1417099720-16428-11-git-send-email-mreitz@redhat.com> In-Reply-To: <1417099720-16428-1-git-send-email-mreitz@redhat.com> References: <1417099720-16428-1-git-send-email-mreitz@redhat.com> Subject: [Qemu-devel] [PATCH v2 10/13] qcow2: Prevent numerical overflow List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org Cc: Kevin Wolf , Peter Lieven , Markus Armbruster , Max Reitz , Stefan Hajnoczi In qcow2_alloc_cluster_offset(), *num is limited to INT_MAX >> BDRV_SECTOR_BITS by all callers. However, since remaining is of type uint64_t, we might as well cast *num to that type before performing the shift. Cc: qemu-stable@nongnu.org Signed-off-by: Max Reitz --- block/qcow2-cluster.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/block/qcow2-cluster.c b/block/qcow2-cluster.c index df0b2c9..1fea514 100644 --- a/block/qcow2-cluster.c +++ b/block/qcow2-cluster.c @@ -1263,7 +1263,7 @@ int qcow2_alloc_cluster_offset(BlockDriverState *bs, uint64_t offset, again: start = offset; - remaining = *num << BDRV_SECTOR_BITS; + remaining = (uint64_t)*num << BDRV_SECTOR_BITS; cluster_offset = 0; *host_offset = 0; cur_bytes = 0; -- 1.9.3