[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [Qemu-stable] [PATCH v5 05/11] linux-user: fix mmap/munmap/mprotect/
From: |
Laurent Vivier |
Subject: |
Re: [Qemu-stable] [PATCH v5 05/11] linux-user: fix mmap/munmap/mprotect/mremap/shmat |
Date: |
Wed, 7 Mar 2018 21:13:42 +0100 |
User-agent: |
Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.6.0 |
Le 07/03/2018 à 18:45, Max Filippov a écrit :
> On Wed, Mar 7, 2018 at 2:08 AM, Laurent Vivier <address@hidden> wrote:
>>> +static inline int guest_range_valid(unsigned long start, unsigned long len)
>>> +{
>>> + if (len)
>>> + return guest_addr_valid(len - 1) && start <= GUEST_ADDR_MAX - len
>>> + 1;
>>> + else
>>> + return guest_addr_valid(start);
>>> +}
>>
>> I think we can consider len == 0 is invalid and use only:
>>
>> return start + (len - 1) <= GUEST_ADDR_MAX;
>
> start + len - 1 may wrap around, that's why I first validate len and then have
> len at the right side of the comparison. I.e. if we drop check for len == 0
> I'd
> still write it as
>
> guest_addr_valid(len - 1) && start <= GUEST_ADDR_MAX - len + 1;
>
Yes, you're right.
it would be clearer to write:
len - 1 <= GUEST_ADDR_MAX && start <= GUEST_ADDR_MAX - len + 1;
but it's only cosmetic.
Thanks,
Laurent