[ovs-discuss] [NIC-20 09/11] vswitchd: Fix use of uninitialized variable in bridge_pick_local_hw_addr().

Ben Pfaff blp at nicira.com
Wed Aug 5 22:37:12 UTC 2009


When a port's MAC is explicitly specified in the config file, we did not
initialize 'iface' and therefore later we could dereference a wild pointer.
This commit fixes the problem.
---
 vswitchd/bridge.c |   14 +++++++++++++-
 1 files changed, 13 insertions(+), 1 deletions(-)

diff --git a/vswitchd/bridge.c b/vswitchd/bridge.c
index a4a723a..12240aa 100644
--- a/vswitchd/bridge.c
+++ b/vswitchd/bridge.c
@@ -631,6 +631,18 @@ bridge_pick_local_hw_addr(struct bridge *br, uint8_t ea[ETH_ADDR_LEN],
         if (iface_ea_u64) {
             /* User specified explicitly. */
             eth_addr_from_uint64(iface_ea_u64, iface_ea);
+
+            /* Find the interface with this Ethernet address (if any) so that
+             * we can provide the correct devname to the caller. */
+            iface = NULL;
+            for (j = 0; j < port->n_ifaces; j++) {
+                struct iface *candidate = port->ifaces[j];
+                uint8_t candidate_ea[ETH_ADDR_LEN];
+                if (!netdev_nodev_get_etheraddr(candidate->name, candidate_ea)
+                    && eth_addr_equals(iface_ea, candidate_ea)) {
+                    iface = candidate;
+                }
+            }
         } else {
             /* Choose the interface whose MAC address will represent the port.
              * The Linux kernel bonding code always chooses the MAC address of
@@ -672,7 +684,7 @@ bridge_pick_local_hw_addr(struct bridge *br, uint8_t ea[ETH_ADDR_LEN],
             memcmp(iface_ea, ea, ETH_ADDR_LEN) < 0)
         {
             memcpy(ea, iface_ea, ETH_ADDR_LEN);
-            *devname = iface->name;
+            *devname = iface ? iface->name : NULL;
         }
     }
     if (eth_addr_is_multicast(ea) || eth_addr_is_vif(ea)) {
-- 
1.6.3.3





More information about the discuss mailing list