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

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

 



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

--
libvir-list mailing list
libvir-list@xxxxxxxxxx
https://www.redhat.com/mailman/listinfo/libvir-list




[Index of Archives]     [Virt Tools]     [Libvirt Users]     [Lib OS Info]     [Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [KDE Users]     [Fedora Tools]