summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKevin Wolf2014-04-14 17:03:34 +0200
committerKevin Wolf2014-04-22 11:57:02 +0200
commit9ce10c0bdcdd8a36c62e3376fd1de86bc0fb8a2a (patch)
treeaaa2965441c8ad2f0ac43548da27a7830a284349
parentblock: Catch integer overflow in bdrv_rw_co() (diff)
downloadqemu-9ce10c0bdcdd8a36c62e3376fd1de86bc0fb8a2a.tar.gz
qemu-9ce10c0bdcdd8a36c62e3376fd1de86bc0fb8a2a.tar.xz
qemu-9ce10c0bdcdd8a36c62e3376fd1de86bc0fb8a2a.zip
block: Check bdrv_getlength() return value in bdrv_make_zero()
Signed-off-by: Kevin Wolf <kwolf@redhat.com> Reviewed-by: Max Reitz <mreitz@redhat.com>
-rw-r--r--block.c8
1 files changed, 7 insertions, 1 deletions
diff --git a/block.c b/block.c
index ec3fa503df..da558774e8 100644
--- a/block.c
+++ b/block.c
@@ -2749,10 +2749,16 @@ int bdrv_write_zeroes(BlockDriverState *bs, int64_t sector_num,
*/
int bdrv_make_zero(BlockDriverState *bs, BdrvRequestFlags flags)
{
- int64_t target_size = bdrv_getlength(bs) / BDRV_SECTOR_SIZE;
+ int64_t target_size;
int64_t ret, nb_sectors, sector_num = 0;
int n;
+ target_size = bdrv_getlength(bs);
+ if (target_size < 0) {
+ return target_size;
+ }
+ target_size /= BDRV_SECTOR_SIZE;
+
for (;;) {
nb_sectors = target_size - sector_num;
if (nb_sectors <= 0) {