From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:47441) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1YQNN2-0001K1-Pf for qemu-devel@nongnu.org; Tue, 24 Feb 2015 16:50:29 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1YQNMo-0005ta-Bw for qemu-devel@nongnu.org; Tue, 24 Feb 2015 16:50:24 -0500 Received: from e39.co.us.ibm.com ([32.97.110.160]:49633) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1YQNMo-0005tC-5V for qemu-devel@nongnu.org; Tue, 24 Feb 2015 16:50:10 -0500 Received: from /spool/local by e39.co.us.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Tue, 24 Feb 2015 14:50:09 -0700 From: Michael Roth Date: Tue, 24 Feb 2015 15:47:45 -0600 Message-Id: <1424814498-6993-11-git-send-email-mdroth@linux.vnet.ibm.com> In-Reply-To: <1424814498-6993-1-git-send-email-mdroth@linux.vnet.ibm.com> References: <1424814498-6993-1-git-send-email-mdroth@linux.vnet.ibm.com> Subject: [Qemu-devel] [PATCH 10/43] qcow2: Prevent numerical overflow List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org Cc: Kevin Wolf , qemu-stable@nongnu.org, Max Reitz From: Max Reitz 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 Reviewed-by: Kevin Wolf Signed-off-by: Kevin Wolf (cherry picked from commit 11c89769dc3e638ef72915d97058411ddf79b64b) Signed-off-by: Michael Roth --- 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.1