]> xenbits.xensource.com Git - libvirt.git/commitdiff
nodeinfo: report error when given node is out of range
authorJincheng Miao <jmiao@redhat.com>
Mon, 22 Sep 2014 10:14:27 +0000 (18:14 +0800)
committerMichal Privoznik <mprivozn@redhat.com>
Tue, 23 Sep 2014 08:23:20 +0000 (10:23 +0200)
https://bugzilla.redhat.com/show_bug.cgi?id=1145050

Signed-off-by: Jincheng Miao <jmiao@redhat.com>
Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
src/nodeinfo.c

index af23b8b2fb6d89343aea512690f4bcfccbd5af95..1b4a8d7d2f82d457d3ef6bdac55724f29d04c236 100644 (file)
@@ -2028,10 +2028,24 @@ nodeGetFreePages(unsigned int npages,
                  unsigned long long *counts)
 {
     int ret = -1;
-    int cell;
+    int cell, lastCell;
     size_t i, ncounts = 0;
 
-    for (cell = startCell; cell < (int) (startCell + cellCount); cell++) {
+    if ((lastCell = virNumaGetMaxNode()) < 0)
+        return 0;
+
+    if (startCell > lastCell) {
+        virReportError(VIR_ERR_INTERNAL_ERROR,
+                       _("start cell %d out of range (0-%d)"),
+                       startCell, lastCell);
+        goto cleanup;
+    }
+
+    lastCell = startCell + cellCount;
+    if (startCell + cellCount < lastCell)
+        lastCell = startCell + cellCount;
+
+    for (cell = startCell; cell < lastCell; cell++) {
         for (i = 0; i < npages; i++) {
             unsigned int page_size = pages[i];
             unsigned int page_free;