summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDan Williams <dcbw@redhat.com>2013-11-11 15:43:13 -0600
committerDan Williams <dcbw@redhat.com>2013-11-11 15:43:13 -0600
commit696f655d7c7b605d0344aeb6ba4ff643cd46a5b4 (patch)
tree376519129dd9934ef8f9443aa116c4a55ea0179b
parent4f3a9cca6f49b471b2843cbe50ad3737105c7d7e (diff)
downloadNetworkManager-696f655d7c7b605d0344aeb6ba4ff643cd46a5b4.tar.gz
ethernet: don't crash if device doesn't have a MAC address (rh #1029053)
Like IBM s390 CTC devices, which aren't really ethernet but for historical reasons we treat them as such.
-rw-r--r--src/devices/nm-device-ethernet.c14
1 files changed, 11 insertions, 3 deletions
diff --git a/src/devices/nm-device-ethernet.c b/src/devices/nm-device-ethernet.c
index 7b1c248eb8..c0b7861eaf 100644
--- a/src/devices/nm-device-ethernet.c
+++ b/src/devices/nm-device-ethernet.c
@@ -310,6 +310,7 @@ update_permanent_hw_address (NMDevice *dev)
struct ifreq req;
struct ethtool_perm_addr *epaddr = NULL;
int fd, ret;
+ const guint8 *mac;
fd = socket (PF_INET, SOCK_DGRAM, 0);
if (fd < 0) {
@@ -332,7 +333,11 @@ update_permanent_hw_address (NMDevice *dev)
nm_log_dbg (LOGD_HW | LOGD_ETHER, "(%s): unable to read permanent MAC address (error %d)",
nm_device_get_iface (dev), errno);
/* Fall back to current address */
- memcpy (epaddr->data, nm_device_get_hw_address (dev, NULL), ETH_ALEN);
+ mac = nm_device_get_hw_address (dev, NULL);
+ if (mac)
+ memcpy (epaddr->data, mac, ETH_ALEN);
+ else
+ memset (epaddr->data, 0, ETH_ALEN);
}
if (memcmp (&priv->perm_hw_addr, epaddr->data, ETH_ALEN)) {
@@ -350,11 +355,14 @@ update_initial_hw_address (NMDevice *dev)
NMDeviceEthernet *self = NM_DEVICE_ETHERNET (dev);
NMDeviceEthernetPrivate *priv = NM_DEVICE_ETHERNET_GET_PRIVATE (self);
char *mac_str;
+ const guint8 *mac;
/* This sets initial MAC address from current MAC address. It should only
* be called from NMDevice constructor() to really get the initial address.
*/
- memcpy (priv->initial_hw_addr, nm_device_get_hw_address (dev, NULL), ETH_ALEN);
+ mac = nm_device_get_hw_address (dev, NULL);
+ if (mac)
+ memcpy (priv->initial_hw_addr, mac, ETH_ALEN);
mac_str = nm_utils_hwaddr_ntoa (priv->initial_hw_addr, ARPHRD_ETHER);
nm_log_dbg (LOGD_DEVICE | LOGD_ETHER, "(%s): read initial MAC address %s",
@@ -1241,7 +1249,7 @@ update_connection (NMDevice *device, NMConnection *connection)
NMDeviceEthernetPrivate *priv = NM_DEVICE_ETHERNET_GET_PRIVATE (device);
NMSettingWired *s_wired = nm_connection_get_setting_wired (connection);
guint maclen;
- gconstpointer mac = nm_device_get_hw_address (device, &maclen);
+ const guint8 *mac = nm_device_get_hw_address (device, &maclen);
static const guint8 null_mac[ETH_ALEN] = { 0, 0, 0, 0, 0, 0 };
const char *mac_prop = NM_SETTING_WIRED_MAC_ADDRESS;
GByteArray *array;