[libvirt] [PATCH 1/5] network: Resolve some issues around vlan copying

John Ferlan jferlan at redhat.com
Tue Jan 15 18:35:34 UTC 2013


Remove extraneous check for 'netdef' when dereferencing for vlan.nTags.
Prior code would already check if netdef was NULL.

Coverity complained about a path where the 'vlan' was potentially valid,
but a prior checks may not have allocated 'iface->data.network.actual',
so like other paths it needs to be allocated on the fly.
---
 src/network/bridge_driver.c | 16 +++++++++++++---
 1 file changed, 13 insertions(+), 3 deletions(-)

diff --git a/src/network/bridge_driver.c b/src/network/bridge_driver.c
index f1be954..e2b8d06 100644
--- a/src/network/bridge_driver.c
+++ b/src/network/bridge_driver.c
@@ -4005,11 +4005,21 @@ networkAllocateActualDevice(virDomainNetDefPtr iface)
         vlan = &iface->vlan;
     else if (portgroup && portgroup->vlan.nTags > 0)
         vlan = &portgroup->vlan;
-    else if (netdef && netdef->vlan.nTags > 0)
+    else if (netdef->vlan.nTags > 0)
         vlan = &netdef->vlan;
 
-    if (virNetDevVlanCopy(&iface->data.network.actual->vlan, vlan) < 0)
-        goto error;
+    if (vlan) {
+        /* data.network.actual may be NULL here when netdef->foward.type is
+         * VIR_NETWORK_FORWARD_{NONE|NAT|ROUTE}
+         */
+        if (!iface->data.network.actual
+            && (VIR_ALLOC(iface->data.network.actual) < 0)) {
+            virReportOOMError();
+            goto error;
+        }
+        if (virNetDevVlanCopy(&iface->data.network.actual->vlan, vlan) < 0)
+            goto error;
+    }
 
 validate:
     /* make sure that everything now specified for the device is
-- 
1.7.11.7




More information about the libvir-list mailing list