]> xenbits.xensource.com Git - libvirt.git/commitdiff
qemu: fix an off-by-one error in qemuDomainGetPercpuStats
authorGuannan Ren <gren@redhat.com>
Wed, 20 Feb 2013 11:28:13 +0000 (19:28 +0800)
committerGuannan Ren <gren@redhat.com>
Thu, 21 Feb 2013 03:27:35 +0000 (11:27 +0800)
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

src/qemu/qemu_driver.c

index 45bd3415995c2e07f55e3d8ec90882e17a79c4cc..e4ace3012541c73e98b357a9f01c6a7615fe9879 100644 (file)
@@ -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++) {