Skip to content

Commit

Permalink
qcow2: Prevent numerical overflow
Browse files Browse the repository at this point in the history
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 <mreitz@redhat.com>
Reviewed-by: Kevin Wolf <kwolf@redhat.com>
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
  • Loading branch information
XanClic authored and kevmw committed Dec 10, 2014
1 parent 2247798 commit 11c8976
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion block/qcow2-cluster.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit 11c8976

Please sign in to comment.