From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:32847) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Y9H0b-0005FO-B2 for qemu-devel@nongnu.org; Thu, 08 Jan 2015 12:36:56 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Y9H09-00070N-F2 for qemu-devel@nongnu.org; Thu, 08 Jan 2015 12:36:33 -0500 Received: from e34.co.us.ibm.com ([32.97.110.152]:37835) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Y9H09-0006zm-8Z for qemu-devel@nongnu.org; Thu, 08 Jan 2015 12:36:05 -0500 Received: from /spool/local by e34.co.us.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Thu, 8 Jan 2015 10:36:04 -0700 From: Michael Roth Date: Thu, 8 Jan 2015 11:34:19 -0600 Message-Id: <1420738472-23267-76-git-send-email-mdroth@linux.vnet.ibm.com> In-Reply-To: <1420738472-23267-1-git-send-email-mdroth@linux.vnet.ibm.com> References: <1420738472-23267-1-git-send-email-mdroth@linux.vnet.ibm.com> Subject: [Qemu-devel] [PATCH 75/88] qcow2: Prevent numerical overflow List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org Cc: qemu-stable@nongnu.org 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 26827a2..769e68d 100644 --- a/block/qcow2-cluster.c +++ b/block/qcow2-cluster.c @@ -1202,7 +1202,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