diff mbox series

[ovs-dev,PATCHv2] netdev: netdev_get_etheraddr is not functioning as advertised.

Message ID 1512059484-2849-1-git-send-email-pkusunyifeng@gmail.com
State Accepted
Headers show
Series [ovs-dev,PATCHv2] netdev: netdev_get_etheraddr is not functioning as advertised. | expand

Commit Message

Yifeng Sun Nov. 30, 2017, 4:31 p.m. UTC
netdev_get_etheraddr claims to clear 'mac' on error, but it fails to do so.
When looking further into both netdev_windows_get_etheraddr() and
netdev_linux_get_etheraddr(), 'mac' is also not cleared. This will lead to
usage of uninitialised ofputil_phy_port.hw_addr.

v1 -> v2: fixed a bug in v1 found by Ben, thanks Ben.

Signed-off-by: Yifeng Sun <pkusunyifeng@gmail.com>
---
 lib/netdev.c | 8 +++++++-
 1 file changed, 7 insertions(+), 1 deletion(-)

Comments

Ben Pfaff Nov. 30, 2017, 9:51 p.m. UTC | #1
On Thu, Nov 30, 2017 at 08:31:24AM -0800, Yifeng Sun wrote:
> netdev_get_etheraddr claims to clear 'mac' on error, but it fails to do so.
> When looking further into both netdev_windows_get_etheraddr() and
> netdev_linux_get_etheraddr(), 'mac' is also not cleared. This will lead to
> usage of uninitialised ofputil_phy_port.hw_addr.
> 
> v1 -> v2: fixed a bug in v1 found by Ben, thanks Ben.
> 
> Signed-off-by: Yifeng Sun <pkusunyifeng@gmail.com>

Thanks, applied to master and backported as far as 2.4.
diff mbox series

Patch

diff --git a/lib/netdev.c b/lib/netdev.c
index c52680659e3f..2d69fe5dac68 100644
--- a/lib/netdev.c
+++ b/lib/netdev.c
@@ -897,7 +897,13 @@  netdev_set_etheraddr(struct netdev *netdev, const struct eth_addr mac)
 int
 netdev_get_etheraddr(const struct netdev *netdev, struct eth_addr *mac)
 {
-    return netdev->netdev_class->get_etheraddr(netdev, mac);
+    int error;
+
+    error = netdev->netdev_class->get_etheraddr(netdev, mac);
+    if (error) {
+        memset(mac, 0, sizeof *mac);
+    }
+    return error;
 }
 
 /* Returns the name of the network device that 'netdev' represents,