9119d9
From 150db6173b1983eb77d9d40a541599dac4ecf0d4 Mon Sep 17 00:00:00 2001
9119d9
Message-Id: <150db6173b1983eb77d9d40a541599dac4ecf0d4@dist-git>
9119d9
From: Jincheng Miao <jmiao@redhat.com>
9119d9
Date: Tue, 23 Sep 2014 10:34:04 +0200
9119d9
Subject: [PATCH] nodeinfo: report error when given node is out of range
9119d9
9119d9
https://bugzilla.redhat.com/show_bug.cgi?id=1145050
9119d9
9119d9
Signed-off-by: Jincheng Miao <jmiao@redhat.com>
9119d9
Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
9119d9
(cherry picked from commit 7db19366423dcab388907c12caf766c6e5870d00)
9119d9
Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
9119d9
---
9119d9
 src/nodeinfo.c | 18 ++++++++++++++++--
9119d9
 1 file changed, 16 insertions(+), 2 deletions(-)
9119d9
9119d9
diff --git a/src/nodeinfo.c b/src/nodeinfo.c
9119d9
index 92a3718..134fee7 100644
9119d9
--- a/src/nodeinfo.c
9119d9
+++ b/src/nodeinfo.c
9119d9
@@ -2032,10 +2032,24 @@ nodeGetFreePages(unsigned int npages,
9119d9
                  unsigned long long *counts)
9119d9
 {
9119d9
     int ret = -1;
9119d9
-    int cell;
9119d9
+    int cell, lastCell;
9119d9
     size_t i, ncounts = 0;
9119d9
 
9119d9
-    for (cell = startCell; cell < (int) (startCell + cellCount); cell++) {
9119d9
+    if ((lastCell = virNumaGetMaxNode()) < 0)
9119d9
+        return 0;
9119d9
+
9119d9
+    if (startCell > lastCell) {
9119d9
+        virReportError(VIR_ERR_INTERNAL_ERROR,
9119d9
+                       _("start cell %d out of range (0-%d)"),
9119d9
+                       startCell, lastCell);
9119d9
+        goto cleanup;
9119d9
+    }
9119d9
+
9119d9
+    lastCell = startCell + cellCount;
9119d9
+    if (startCell + cellCount < lastCell)
9119d9
+        lastCell = startCell + cellCount;
9119d9
+
9119d9
+    for (cell = startCell; cell < lastCell; cell++) {
9119d9
         for (i = 0; i < npages; i++) {
9119d9
             unsigned int page_size = pages[i];
9119d9
             unsigned int page_free;
9119d9
-- 
9119d9
2.1.1
9119d9