2007-11-15 Dan Williams <dcbw@redhat.com>

* src/NetworkManagerUtils.c
		- (nm_ethernet_address_is_valid): fix style, clarify
		- (nm_ethernet_addresses_are_equal): don't try to memcmp NULLs

	* src/nm-device-802-11-wireless.c
		- (get_active_ap): handle failure from nm_device_802_11_wireless_get_bssid()
		- (nm_device_802_11_wireless_get_ssid,
		   nm_device_802_11_wireless_get_bssid,
		   nm_device_802_11_wireless_get_bitrate): zero the wreq structure
		   	before calling the ioctl; fixes valgrind-reported jump depends on
			uninitialized value errors



git-svn-id: http://svn-archive.gnome.org/svn/NetworkManager/trunk@3086 4912f4e0-d625-0410-9fb7-b9a5a253dbdc
This commit is contained in:
Dan Williams
2007-11-15 18:33:17 +00:00
parent 53f271805f
commit da4f9c0df2
3 changed files with 63 additions and 27 deletions

View File

@@ -1,3 +1,17 @@
2007-11-15 Dan Williams <dcbw@redhat.com>
* src/NetworkManagerUtils.c
- (nm_ethernet_address_is_valid): fix style, clarify
- (nm_ethernet_addresses_are_equal): don't try to memcmp NULLs
* src/nm-device-802-11-wireless.c
- (get_active_ap): handle failure from nm_device_802_11_wireless_get_bssid()
- (nm_device_802_11_wireless_get_ssid,
nm_device_802_11_wireless_get_bssid,
nm_device_802_11_wireless_get_bitrate): zero the wreq structure
before calling the ioctl; fixes valgrind-reported jump depends on
uninitialized value errors
2007-11-15 Dan Williams <dcbw@redhat.com>
* libnm-util/nm-setting.c

View File

@@ -202,25 +202,33 @@ int nm_null_safe_strcmp (const char *s1, const char *s2)
* Compares an Ethernet address against known invalid addresses.
*
*/
gboolean nm_ethernet_address_is_valid (const struct ether_addr *test_addr)
gboolean
nm_ethernet_address_is_valid (const struct ether_addr *test_addr)
{
gboolean valid = FALSE;
struct ether_addr invalid_addr1 = { {0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF} };
struct ether_addr invalid_addr2 = { {0x00, 0x00, 0x00, 0x00, 0x00, 0x00} };
struct ether_addr invalid_addr3 = { {0x44, 0x44, 0x44, 0x44, 0x44, 0x44} };
struct ether_addr invalid_addr4 = { {0x00, 0x30, 0xb4, 0x00, 0x00, 0x00} }; /* prism54 dummy MAC */
guint8 invalid_addr1[ETH_ALEN] = {0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF};
guint8 invalid_addr2[ETH_ALEN] = {0x00, 0x00, 0x00, 0x00, 0x00, 0x00};
guint8 invalid_addr3[ETH_ALEN] = {0x44, 0x44, 0x44, 0x44, 0x44, 0x44};
guint8 invalid_addr4[ETH_ALEN] = {0x00, 0x30, 0xb4, 0x00, 0x00, 0x00}; /* prism54 dummy MAC */
g_return_val_if_fail (test_addr != NULL, FALSE);
/* Compare the AP address the card has with invalid ethernet MAC addresses. */
if ( (memcmp(test_addr, &invalid_addr1, sizeof(struct ether_addr)) != 0)
&& (memcmp(test_addr, &invalid_addr2, sizeof(struct ether_addr)) != 0)
&& (memcmp(test_addr, &invalid_addr3, sizeof(struct ether_addr)) != 0)
&& (memcmp(test_addr, &invalid_addr4, sizeof(struct ether_addr)) != 0)
&& ((test_addr->ether_addr_octet[0] & 1) == 0)) /* Multicast addresses */
valid = TRUE;
if (memcmp (test_addr->ether_addr_octet, &invalid_addr1, ETH_ALEN))
return FALSE;
return (valid);
if (memcmp (test_addr->ether_addr_octet, &invalid_addr2, ETH_ALEN))
return FALSE;
if (memcmp (test_addr->ether_addr_octet, &invalid_addr3, ETH_ALEN))
return FALSE;
if (memcmp (test_addr->ether_addr_octet, &invalid_addr4, ETH_ALEN))
return FALSE;
if (test_addr->ether_addr_octet[0] & 1) /* Multicast addresses */
return FALSE;
return TRUE;
}
@@ -229,8 +237,12 @@ gboolean nm_ethernet_address_is_valid (const struct ether_addr *test_addr)
*
* Compare two Ethernet addresses and return TRUE if equal and FALSE if not.
*/
gboolean nm_ethernet_addresses_are_equal (const struct ether_addr *a, const struct ether_addr *b)
gboolean
nm_ethernet_addresses_are_equal (const struct ether_addr *a, const struct ether_addr *b)
{
g_return_val_if_fail (a != NULL, FALSE);
g_return_val_if_fail (b != NULL, FALSE);
if (memcmp (a, b, sizeof (struct ether_addr)))
return FALSE;
return TRUE;

View File

@@ -496,7 +496,7 @@ static NMAccessPoint *
get_active_ap (NMDevice80211Wireless *self,
NMAccessPoint *ignore_ap)
{
struct ether_addr bssid;
struct ether_addr bssid = {0x0, 0x0, 0x0, 0x0, 0x0, 0x0};
const GByteArray *ssid;
GSList *iter;
@@ -1196,6 +1196,7 @@ nm_device_802_11_wireless_get_ssid (NMDevice80211Wireless *self)
return NULL;
}
memset (ssid, 0, sizeof (ssid));
wrq.u.essid.pointer = (caddr_t) &ssid;
wrq.u.essid.length = sizeof (ssid);
wrq.u.essid.flags = 0;
@@ -1316,11 +1317,14 @@ nm_device_802_11_wireless_get_bitrate (NMDevice80211Wireless *self)
g_return_val_if_fail (self != NULL, 0);
iface = nm_device_get_iface (NM_DEVICE (self));
if ((sk = nm_dev_sock_open (iface, DEV_WIRELESS, __FUNCTION__, NULL))) {
sk = nm_dev_sock_open (iface, DEV_WIRELESS, __func__, NULL);
if (!sk)
return 0;
nm_ioctl_info ("%s: About to GET IWRATE.", iface);
memset (&wrq, 0, sizeof (wrq));
err = iw_get_ext (nm_dev_sock_get_fd (sk), iface, SIOCGIWRATE, &wrq);
nm_dev_sock_close (sk);
}
return ((err >= 0) ? wrq.u.bitrate.value : 0);
}
@@ -1338,6 +1342,7 @@ nm_device_802_11_wireless_get_bssid (NMDevice80211Wireless *self,
NMSock * sk;
struct iwreq wrq;
const char * iface;
gboolean success = FALSE;
g_return_if_fail (self != NULL);
g_return_if_fail (bssid != NULL);
@@ -1345,13 +1350,18 @@ nm_device_802_11_wireless_get_bssid (NMDevice80211Wireless *self,
memset (bssid, 0, sizeof (struct ether_addr));
iface = nm_device_get_iface (NM_DEVICE (self));
if ((sk = nm_dev_sock_open (iface, DEV_WIRELESS, __FUNCTION__, NULL)))
{
nm_ioctl_info ("%s: About to GET IWAP.", iface);
if (iw_get_ext (nm_dev_sock_get_fd (sk), iface, SIOCGIWAP, &wrq) >= 0)
memcpy (bssid, &(wrq.u.ap_addr.sa_data), sizeof (struct ether_addr));
nm_dev_sock_close (sk);
sk = nm_dev_sock_open (iface, DEV_WIRELESS, __func__, NULL);
if (!sk) {
g_warning ("%s: failed to open device socket.", __func__);
return;
}
nm_ioctl_info ("%s: About to GET IWAP.", iface);
memset (&wrq, 0, sizeof (wrq));
if (iw_get_ext (nm_dev_sock_get_fd (sk), iface, SIOCGIWAP, &wrq) >= 0)
memcpy (bssid->ether_addr_octet, &(wrq.u.ap_addr.sa_data), ETH_ALEN);
nm_dev_sock_close (sk);
}
@@ -2729,7 +2739,7 @@ activation_success_handler (NMDevice *dev)
{
NMDevice80211Wireless *self = NM_DEVICE_802_11_WIRELESS (dev);
NMAccessPoint *ap;
struct ether_addr bssid;
struct ether_addr bssid = {0x0, 0x0, 0x0, 0x0, 0x0, 0x0};
NMAccessPoint *tmp_ap;
ap = nm_device_802_11_wireless_get_activation_ap (self);