[PATCH] virnetdev: Resolve some Coverity issues

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

 



Coverity discovered a few issues with recent changes in this module
from commit id 'cc0e8c24'.  This patches fixes those.

Signed-off-by: John Ferlan <jferlan@xxxxxxxxxx>
---
 src/util/virnetdev.c | 37 +++++++++++++++++++++----------------
 1 file changed, 21 insertions(+), 16 deletions(-)

diff --git a/src/util/virnetdev.c b/src/util/virnetdev.c
index 127bfb2..8bd1af4 100644
--- a/src/util/virnetdev.c
+++ b/src/util/virnetdev.c
@@ -59,15 +59,20 @@ VIR_LOG_INIT("util.netdev");
 #define PROC_NET_DEV_MCAST "/proc/net/dev_mcast"
 #define MAX_MCAST_SIZE 50*14336
 #define VIR_MCAST_NAME_LEN (IFNAMSIZ + 1)
-#define VIR_MCAST_INDEX_TOKEN_IDX 0
-#define VIR_MCAST_NAME_TOKEN_IDX 1
-#define VIR_MCAST_USERS_TOKEN_IDX 2
-#define VIR_MCAST_GLOBAL_TOKEN_IDX 3
-#define VIR_MCAST_ADDR_TOKEN_IDX 4
 #define VIR_MCAST_NUM_TOKENS 5
 #define VIR_MCAST_TOKEN_DELIMS " \n"
 #define VIR_MCAST_ADDR_LEN (VIR_MAC_HEXLEN + 1)
 
+typedef enum {
+    VIR_MCAST_TYPE_INDEX_TOKEN,
+    VIR_MCAST_TYPE_NAME_TOKEN,
+    VIR_MCAST_TYPE_USERS_TOKEN,
+    VIR_MCAST_TYPE_GLOBAL_TOKEN,
+    VIR_MCAST_TYPE_ADDR_TOKEN,
+
+    VIR_MCAST_TYPE_LAST
+} virMCastType;
+
 typedef struct _virNetDevMcastEntry virNetDevMcastEntry;
 typedef virNetDevMcastEntry *virNetDevMcastEntryPtr;
 struct _virNetDevMcastEntry  {
@@ -2076,7 +2081,7 @@ static int virNetDevParseMcast(char *buf, virNetDevMcastEntryPtr mcast)
     char *saveptr;
     char *endptr;
 
-    for (ifindex = 0, next = buf; ifindex < VIR_MCAST_NUM_TOKENS; ifindex++,
+    for (ifindex = 0, next = buf; ifindex < VIR_MCAST_TYPE_LAST; ifindex++,
          next = NULL) {
         token = strtok_r(next, VIR_MCAST_TOKEN_DELIMS, &saveptr);
 
@@ -2087,8 +2092,8 @@ static int virNetDevParseMcast(char *buf, virNetDevMcastEntryPtr mcast)
             return -1;
         }
 
-        switch (ifindex) {
-            case VIR_MCAST_INDEX_TOKEN_IDX:
+        switch ((virMCastType)ifindex) {
+            case VIR_MCAST_TYPE_INDEX_TOKEN:
                 if (virStrToLong_i(token, &endptr, 10, &num) < 0) {
                     virReportSystemError(EINVAL,
                                          _("Failed to parse interface index from '%s'"),
@@ -2098,7 +2103,7 @@ static int virNetDevParseMcast(char *buf, virNetDevMcastEntryPtr mcast)
                 }
                 mcast->index = num;
                 break;
-            case VIR_MCAST_NAME_TOKEN_IDX:
+            case VIR_MCAST_TYPE_NAME_TOKEN:
                 if (virStrncpy(mcast->name, token, strlen(token),
                     VIR_MCAST_NAME_LEN) == NULL) {
                     virReportSystemError(EINVAL,
@@ -2107,7 +2112,7 @@ static int virNetDevParseMcast(char *buf, virNetDevMcastEntryPtr mcast)
                     return -1;
                 }
                 break;
-            case VIR_MCAST_USERS_TOKEN_IDX:
+            case VIR_MCAST_TYPE_USERS_TOKEN:
                 if (virStrToLong_i(token, &endptr, 10, &num) < 0) {
                     virReportSystemError(EINVAL,
                                          _("Failed to parse users from '%s'"),
@@ -2117,7 +2122,7 @@ static int virNetDevParseMcast(char *buf, virNetDevMcastEntryPtr mcast)
                 }
                 mcast->users = num;
                 break;
-            case VIR_MCAST_GLOBAL_TOKEN_IDX:
+            case VIR_MCAST_TYPE_GLOBAL_TOKEN:
                 if (virStrToLong_i(token, &endptr, 10, &num) < 0) {
                     virReportSystemError(EINVAL,
                                          _("Failed to parse users from '%s'"),
@@ -2127,7 +2132,7 @@ static int virNetDevParseMcast(char *buf, virNetDevMcastEntryPtr mcast)
                 }
                 mcast->global = num;
                 break;
-            case VIR_MCAST_ADDR_TOKEN_IDX:
+            case VIR_MCAST_TYPE_ADDR_TOKEN:
                 if (virMacAddrParseHex((const char*)token,
                     &mcast->macaddr) < 0) {
                     virReportSystemError(EINVAL,
@@ -2135,7 +2140,9 @@ static int virNetDevParseMcast(char *buf, virNetDevMcastEntryPtr mcast)
                                          buf);
                 }
                 break;
-            default:
+
+            /* coverity[dead_error_begin] */
+            case VIR_MCAST_TYPE_LAST:
                 break;
         }
     }
@@ -2194,9 +2201,7 @@ static int virNetDevGetMcastList(const char *ifname,
 
     ret = 0;
  cleanup:
-    if (ret < 0)
-        virNetDevMcastListClear(mcast);
-
+    VIR_FREE(buf);
     VIR_FREE(entry);
 
     return ret;
-- 
1.9.3

--
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]