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

Re: [libvirt] [PATCH] domain controller index check



@Jan

could you please review this patch?

----- Original Message -----
From: "Jincheng Miao" <jmiao redhat com>
To: libvir-list redhat com
Cc: "Jincheng Miao" <jmiao redhat com>
Sent: Tuesday, July 9, 2013 12:13:44 PM
Subject: [libvirt][PATCH] domain controller index check

The index of the controller should not be limited in [zero, INT_MAX].
So use virStrToLong_ui() and check the limit of the controller
index in virDomainControllerDefParseXML().
---
 src/conf/domain_conf.c  | 6 +++---
 src/conf/domain_conf.h  | 2 +-
 src/qemu/qemu_command.c | 2 +-
 src/vmx/vmx.c           | 3 +--
 4 files changed, 6 insertions(+), 7 deletions(-)

diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c
index 402e6e9..d4c1054 100644
--- a/src/conf/domain_conf.c
+++ b/src/conf/domain_conf.c
@@ -2655,7 +2655,7 @@ virDomainDefRejectDuplicateControllers(virDomainDefPtr def)
 
     for (i = 0; i < def->ncontrollers; i++) {
         cont = def->controllers[i];
-        if (cont->idx > max_idx[cont->type])
+        if ((int)cont->idx > max_idx[cont->type])
             max_idx[cont->type] = cont->idx;
     }
 
@@ -2663,7 +2663,7 @@ virDomainDefRejectDuplicateControllers(virDomainDefPtr def)
     max_idx[VIR_DOMAIN_CONTROLLER_TYPE_USB] = -1;
 
     for (i = 0; i < VIR_DOMAIN_CONTROLLER_TYPE_LAST; i++) {
-        if (max_idx[i] >= 0 && !(bitmaps[i] = virBitmapNew(max_idx[i] + 1)))
+        if (max_idx[i] >= 0 && !(bitmaps[i] = virBitmapNew((size_t)max_idx[i] + 1)))
             goto no_memory;
         nbitmaps++;
     }
@@ -5593,7 +5593,7 @@ virDomainControllerDefParseXML(xmlNodePtr node,
 
     idx = virXMLPropString(node, "index");
     if (idx) {
-        if (virStrToLong_i(idx, NULL, 10, &def->idx) < 0) {
+        if (virStrToLong_ui(idx, NULL, 10, &def->idx) < 0 || def->idx > INT_MAX) {
             virReportError(VIR_ERR_INTERNAL_ERROR,
                            _("Cannot parse controller index %s"), idx);
             goto error;
diff --git a/src/conf/domain_conf.h b/src/conf/domain_conf.h
index da83eb6..7897b4b 100644
--- a/src/conf/domain_conf.h
+++ b/src/conf/domain_conf.h
@@ -790,7 +790,7 @@ struct _virDomainVirtioSerialOpts {
 /* Stores the virtual disk controller configuration */
 struct _virDomainControllerDef {
     int type;
-    int idx;
+    unsigned int idx;
     int model; /* -1 == undef */
     unsigned int queues;
     union {
diff --git a/src/qemu/qemu_command.c b/src/qemu/qemu_command.c
index 46db28a..7fd1cbf 100644
--- a/src/qemu/qemu_command.c
+++ b/src/qemu/qemu_command.c
@@ -1585,7 +1585,7 @@ qemuDomainAssignPCIAddresses(virDomainDefPtr def,
 
         for (i = 0; i < def->ncontrollers; i++) {
             if (def->controllers[i]->type == VIR_DOMAIN_CONTROLLER_TYPE_PCI) {
-                if (def->controllers[i]->idx > max_idx)
+                if ((int)def->controllers[i]->idx > max_idx)
                     max_idx = def->controllers[i]->idx;
             }
         }
diff --git a/src/vmx/vmx.c b/src/vmx/vmx.c
index 5464d13..deddfaa 100644
--- a/src/vmx/vmx.c
+++ b/src/vmx/vmx.c
@@ -1664,8 +1664,7 @@ virVMXParseConfig(virVMXContext *ctx,
 
     for (controller = 0; controller < def->ncontrollers; ++controller) {
         if (def->controllers[controller]->type == VIR_DOMAIN_CONTROLLER_TYPE_SCSI) {
-            if (def->controllers[controller]->idx < 0 ||
-                def->controllers[controller]->idx > 3) {
+            if (def->controllers[controller]->idx > 3) {
                 virReportError(VIR_ERR_INTERNAL_ERROR,
                                _("SCSI controller index %d out of [0..3] range"),
                                def->controllers[controller]->idx);
-- 
1.8.3.1


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