[PATCH] util: fix bug found by Coverity

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

 



Commit 861d40565 added code (my personal change to "clean up" the
submitter's code, *not* the fault of the submitter) that dereferenced
virtVlan without first checking for NULL. This patch fixes that and,
as part of the fix, cleans up some unnecessary obtuseness.
---
John - Does this eliminate the Coverity complaints?

 src/util/virnetdevopenvswitch.c | 48 ++++++++++++++++++++---------------------
 1 file changed, 24 insertions(+), 24 deletions(-)

diff --git a/src/util/virnetdevopenvswitch.c b/src/util/virnetdevopenvswitch.c
index 5834e4e..75b196c 100644
--- a/src/util/virnetdevopenvswitch.c
+++ b/src/util/virnetdevopenvswitch.c
@@ -81,9 +81,27 @@ int virNetDevOpenvswitchAddPort(const char *brname, const char *ifname,
             goto out_of_memory;
     }
 
+    cmd = virCommandNew(OVSVSCTL);
+
+    virCommandAddArgList(cmd, "--timeout=5", "--", "--may-exist", "add-port",
+                        brname, ifname, NULL);
+
     if (virtVlan && virtVlan->nTags > 0) {
 
-        /* Trunk port first */
+        switch (virtVlan->nativeMode) {
+        case VIR_NATIVE_VLAN_MODE_TAGGED:
+            virCommandAddArg(cmd, "vlan_mode=native-tagged");
+            virCommandAddArgFormat(cmd, "tag=%d", virtVlan->nativeTag);
+            break;
+        case VIR_NATIVE_VLAN_MODE_UNTAGGED:
+            virCommandAddArg(cmd, "vlan_mode=native-untagged");
+            virCommandAddArgFormat(cmd, "tag=%d", virtVlan->nativeTag);
+            break;
+        case VIR_NATIVE_VLAN_MODE_DEFAULT:
+        default:
+            break;
+        }
+
         if (virtVlan->trunk) {
             virBufferAddLit(&buf, "trunk=");
 
@@ -99,33 +117,15 @@ int virNetDevOpenvswitchAddPort(const char *brname, const char *ifname,
                 virBufferAddLit(&buf, ",");
                 virBufferAsprintf(&buf, "%d", virtVlan->tag[i]);
             }
+
+            if (virBufferError(&buf))
+                goto out_of_memory;
+            virCommandAddArg(cmd, virBufferCurrentContent(&buf));
         } else if (virtVlan->nTags) {
-            virBufferAsprintf(&buf, "tag=%d", virtVlan->tag[0]);
+            virCommandAddArgFormat(cmd, "tag=%d", virtVlan->tag[0]);
         }
     }
 
-    cmd = virCommandNew(OVSVSCTL);
-
-    virCommandAddArgList(cmd, "--timeout=5", "--", "--may-exist", "add-port",
-                        brname, ifname, NULL);
-
-    switch (virtVlan->nativeMode) {
-    case VIR_NATIVE_VLAN_MODE_TAGGED:
-        virCommandAddArg(cmd, "vlan_mode=native-tagged");
-        virCommandAddArgFormat(cmd, "tag=%d", virtVlan->nativeTag);
-        break;
-    case VIR_NATIVE_VLAN_MODE_UNTAGGED:
-        virCommandAddArg(cmd, "vlan_mode=native-untagged");
-        virCommandAddArgFormat(cmd, "tag=%d", virtVlan->nativeTag);
-        break;
-    case VIR_NATIVE_VLAN_MODE_DEFAULT:
-    default:
-        break;
-    }
-
-    if (virBufferUse(&buf) != 0)
-        virCommandAddArgList(cmd, virBufferCurrentContent(&buf), NULL);
-
     if (ovsport->profileID[0] == '\0') {
         virCommandAddArgList(cmd,
                         "--", "set", "Interface", ifname, attachedmac_ex_id,
-- 
1.7.11.7

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