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

[libvirt] [PATCH 5/7] virsh-nodedev: Resolve Coverity issues



Recent changes uncovered FORWARD_NULL and NEGATIVE_RETURNS problems with
the processing of the 'ndevices' and its associated allocated arrays in
'vshNodeDeviceListCollect' due to the possibility of returning -1 in a
call and using the returned value as a for loop index end condition.
---
 tools/virsh-nodedev.c | 12 +++++++-----
 1 file changed, 7 insertions(+), 5 deletions(-)

diff --git a/tools/virsh-nodedev.c b/tools/virsh-nodedev.c
index 2eb1979..d22e1c6 100644
--- a/tools/virsh-nodedev.c
+++ b/tools/virsh-nodedev.c
@@ -234,6 +234,7 @@ vshNodeDeviceListCollect(vshControl *ctl,
     size_t deleted = 0;
     int ndevices = 0;
     char **names = NULL;
+    int rc;
 
     /* try the list with flags support (0.10.2 and later) */
     if ((ret = virConnectListAllNodeDevices(ctl->conn,
@@ -256,19 +257,20 @@ fallback:
     /* fall back to old method (0.10.1 and older) */
     vshResetLibvirtError();
 
-    ndevices = virNodeNumOfDevices(ctl->conn, NULL, 0);
-    if (ndevices < 0) {
+    rc = virNodeNumOfDevices(ctl->conn, NULL, 0);
+    if (rc < 0) {
         vshError(ctl, "%s", _("Failed to count node devices"));
         goto cleanup;
     }
 
-    if (ndevices == 0)
+    if (rc == 0)
         return list;
 
+    ndevices = rc;
     names = vshMalloc(ctl, sizeof(char *) * ndevices);
 
-    ndevices = virNodeListDevices(ctl->conn, NULL, names, ndevices, 0);
-    if (ndevices < 0) {
+    rc = virNodeListDevices(ctl->conn, NULL, names, ndevices, 0);
+    if (rc < 0) {
         vshError(ctl, "%s", _("Failed to list node devices"));
         goto cleanup;
     }
-- 
1.8.1.4


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