From: Guannan Ren Date: Wed, 20 Feb 2013 11:28:13 +0000 (+0800) Subject: qemu: fix an off-by-one error in qemuDomainGetPercpuStats X-Git-Tag: v1.0.3-rc1~65 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=091831633f91009379ff9daf2dc98f917aefa12f;p=thirdparty%2Flibvirt.git qemu: fix an off-by-one error in qemuDomainGetPercpuStats 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 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 --- diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c index 45bd341599..e4ace30125 100644 --- a/src/qemu/qemu_driver.c +++ b/src/qemu/qemu_driver.c @@ -14331,9 +14331,9 @@ qemuDomainGetPercpuStats(virDomainObjPtr vm, param_idx = 0; /* number of cpus to compute */ - id = max_id; - - if (max_id - start_cpu > ncpus - 1) + if (start_cpu >= max_id - ncpus) + id = max_id - 1; + else id = start_cpu + ncpus - 1; for (i = 0; i <= id; i++) {