Re: [PATCH] qemu: fix an off-by-one error in qemuDomainGetPercpuStats

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

 



On 02/20/2013 04:51 AM, Guannan Ren wrote:
> The max value of number of cpus to compute(id) should not
> be equal or greater than max cpu number.
> The bug ocurrs when id value is equal to max cpu number which

s/ocurrs/occurs/

> leads to the off-by-one error in the following for loop.
> 
>  # virsh  cpu-stats guest --start 1
>  error: Failed to virDomainGetCPUStats()
> 
>  error: internal error cpuacct parse error
> ---
>  src/qemu/qemu_driver.c | 6 +++---
>  1 file changed, 3 insertions(+), 3 deletions(-)


>      /* number of cpus to compute */
> -    id = max_id;
> -
> -    if (max_id - start_cpu > ncpus - 1)

The old code was trying to avoid the possibility of integer overflow, by
only using subtraction (src/libvirt.c already ensured we have
non-negative values, but not necessarily that the sum of two positive
values won't wrap around to negative).

> +    if ((start_cpu + ncpus) >= max_id)

The new code is not as careful, and has redundant ().

ACK if you change this to the equivalent:

if (start_cpu >= max_id - ncpus)

> +        id = max_id - 1;
> +    else
>          id = start_cpu + ncpus - 1;
>  
>      for (i = 0; i <= id; i++) {
> 

-- 
Eric Blake   eblake redhat com    +1-919-301-3266
Libvirt virtualization library http://libvirt.org

Attachment: signature.asc
Description: OpenPGP digital signature

--
libvir-list mailing list
libvir-list@xxxxxxxxxx
https://www.redhat.com/mailman/listinfo/libvir-list

[Index of Archives]     [Virt Tools]     [Libvirt Users]     [Lib OS Info]     [Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [KDE Users]     [Fedora Tools]