qemu-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Qemu-devel] [Qemu-block] [PATCH 1/2] block: Detect multiplication o


From: Alberto Garcia
Subject: Re: [Qemu-devel] [Qemu-block] [PATCH 1/2] block: Detect multiplication overflow in bdrv_getlength
Date: Fri, 15 May 2015 10:04:04 +0200
User-agent: Notmuch/0.13.2 (http://notmuchmail.org) Emacs/23.2.1 (i486-pc-linux-gnu)

On Fri 15 May 2015 03:39:10 AM CEST, Fam Zheng <address@hidden> wrote:

>      int64_t ret = bdrv_nb_sectors(bs);
>  
> +    ret = (int64_t)(ret * BDRV_SECTOR_SIZE) < 0 ? -EFBIG : ret;
>      return ret < 0 ? ret : ret * BDRV_SECTOR_SIZE;

Maybe in this case you're safe, but in general there's no guarantee that
if there's an overflow the result will be negative.

You can do something like this instead:

   ret = ret > INT64_MAX / BDRV_SECTOR_SIZE ? -EFBIG : ret;

Of course this is only valid if BDRV_SECTOR_SIZE != 0 ;)

Berto



reply via email to

[Prev in Thread] Current Thread [Next in Thread]