qemu-devel
[Top][All Lists]
Advanced

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

Re: [Qemu-devel] [PATCH] memfd: Avoid Coverity warning about integer ove


From: Paolo Bonzini
Subject: Re: [Qemu-devel] [PATCH] memfd: Avoid Coverity warning about integer overflow
Date: Wed, 16 May 2018 09:23:47 +0200
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.7.0

On 15/05/2018 19:27, Peter Maydell wrote:
> Coverity complains about qemu_memfd_create() (CID 1385858) because
> we calculate a bit position htsize which could be up to 63, but
> then use it in "1 << htsize" which is a 32-bit integer calculation
> and could push the 1 off the top of the value.
> 
> Silence the complaint bu using "1ULL"; this isn't a bug in
> practice since a hugetlbsize of 4GB is not very plausible.
> 
> Signed-off-by: Peter Maydell <address@hidden>
> ---
>  util/memfd.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/util/memfd.c b/util/memfd.c
> index b3ecbac19e..d248a53c3c 100644
> --- a/util/memfd.c
> +++ b/util/memfd.c
> @@ -66,7 +66,7 @@ int qemu_memfd_create(const char *name, size_t size, bool 
> hugetlb,
>  {
>      int htsize = hugetlbsize ? ctz64(hugetlbsize) : 0;
>  
> -    if (htsize && 1 << htsize != hugetlbsize) {
> +    if (htsize && 1ULL << htsize != hugetlbsize) {
>          error_setg(errp, "Hugepage size must be a power of 2");
>          return -1;
>      }
> 

Queued, thanks.

Paolo



reply via email to

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