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

[libvirt] [PATCH] Fix off-by-one check in QEMU memory stats



The QEMU memory stats JSON monitor command was too cautious in
checking array bounds, dropping the last requested stat

* src/qemu/qemu_monitor_json.c: Fix off-by-1 check in memory
  stats
---
 src/qemu/qemu_monitor_json.c |   12 ++++++------
 1 files changed, 6 insertions(+), 6 deletions(-)

diff --git a/src/qemu/qemu_monitor_json.c b/src/qemu/qemu_monitor_json.c
index 7c0d372..3c97e9d 100644
--- a/src/qemu/qemu_monitor_json.c
+++ b/src/qemu/qemu_monitor_json.c
@@ -965,7 +965,7 @@ int qemuMonitorJSONGetMemoryStats(qemuMonitorPtr mon,
                 goto cleanup;
             }
 
-            if (virJSONValueObjectHasKey(data, "mem_swapped_in") && (got < (nr_stats-1))) {
+            if (virJSONValueObjectHasKey(data, "mem_swapped_in") && (got < nr_stats)) {
                 if (virJSONValueObjectGetNumberUlong(data, "mem_swapped_in", &mem) < 0) {
                     qemuReportError(VIR_ERR_INTERNAL_ERROR, "%s",
                                     _("info balloon reply was missing balloon mem_swapped_in"));
@@ -976,7 +976,7 @@ int qemuMonitorJSONGetMemoryStats(qemuMonitorPtr mon,
                 stats[got].val = (mem/1024);
                 got++;
             }
-            if (virJSONValueObjectHasKey(data, "mem_swapped_out") && (got < (nr_stats-1))) {
+            if (virJSONValueObjectHasKey(data, "mem_swapped_out") && (got < nr_stats)) {
                 if (virJSONValueObjectGetNumberUlong(data, "mem_swapped_out", &mem) < 0) {
                     qemuReportError(VIR_ERR_INTERNAL_ERROR, "%s",
                                     _("info balloon reply was missing balloon mem_swapped_out"));
@@ -987,7 +987,7 @@ int qemuMonitorJSONGetMemoryStats(qemuMonitorPtr mon,
                 stats[got].val = (mem/1024);
                 got++;
             }
-            if (virJSONValueObjectHasKey(data, "major_page_faults") && (got < (nr_stats-1))) {
+            if (virJSONValueObjectHasKey(data, "major_page_faults") && (got < nr_stats)) {
                 if (virJSONValueObjectGetNumberUlong(data, "major_page_faults", &mem) < 0) {
                     qemuReportError(VIR_ERR_INTERNAL_ERROR, "%s",
                                     _("info balloon reply was missing balloon major_page_faults"));
@@ -998,7 +998,7 @@ int qemuMonitorJSONGetMemoryStats(qemuMonitorPtr mon,
                 stats[got].val = mem;
                 got++;
             }
-            if (virJSONValueObjectHasKey(data, "minor_page_faults") && (got < (nr_stats-1))) {
+            if (virJSONValueObjectHasKey(data, "minor_page_faults") && (got < nr_stats)) {
                 if (virJSONValueObjectGetNumberUlong(data, "minor_page_faults", &mem) < 0) {
                     qemuReportError(VIR_ERR_INTERNAL_ERROR, "%s",
                                     _("info balloon reply was missing balloon minor_page_faults"));
@@ -1009,7 +1009,7 @@ int qemuMonitorJSONGetMemoryStats(qemuMonitorPtr mon,
                 stats[got].val = mem;
                 got++;
             }
-            if (virJSONValueObjectHasKey(data, "free_mem") && (got < (nr_stats-1))) {
+            if (virJSONValueObjectHasKey(data, "free_mem") && (got < nr_stats)) {
                 if (virJSONValueObjectGetNumberUlong(data, "free_mem", &mem) < 0) {
                     qemuReportError(VIR_ERR_INTERNAL_ERROR, "%s",
                                     _("info balloon reply was missing balloon free_mem"));
@@ -1020,7 +1020,7 @@ int qemuMonitorJSONGetMemoryStats(qemuMonitorPtr mon,
                 stats[got].val = (mem/1024);
                 got++;
             }
-            if (virJSONValueObjectHasKey(data, "total_mem") && (got < (nr_stats-1))) {
+            if (virJSONValueObjectHasKey(data, "total_mem") && (got < nr_stats)) {
                 if (virJSONValueObjectGetNumberUlong(data, "total_mem", &mem) < 0) {
                     qemuReportError(VIR_ERR_INTERNAL_ERROR, "%s",
                                     _("info balloon reply was missing balloon total_mem"));
-- 
1.6.6.1


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