platform: ensure ext-data is of expected type

We just lookup the link info by ifindex. There is no guarantee that that
ifindex is of the expected type, to have a suitable ext-data. Check for
that.

Fixes: a7d2cad67e ('platform/linux: add support for WPAN links')
This commit is contained in:
Thomas Haller 2023-02-24 10:13:43 +01:00
parent 61c0971748
commit 6dafe78088
No known key found for this signature in database
GPG key ID: 29C2366E4DFC5728

View file

@ -9213,15 +9213,27 @@ get_ext_data(NMPlatform *platform, int ifindex)
return obj->_link.ext_data;
}
#define get_ext_data_check(platform, ifindex, is_check) \
({ \
GObject *_obj = get_ext_data((platform), (ifindex)); \
\
_obj &&is_check(_obj) ? ((gpointer) _obj) : NULL; \
})
/*****************************************************************************/
#define WIFI_GET_WIFI_DATA_NETNS(wifi_data, platform, ifindex, retval) \
nm_auto_pop_netns NMPNetns *netns = NULL; \
NMWifiUtils *wifi_data; \
if (!nm_platform_netns_push(platform, &netns)) \
return retval; \
wifi_data = NM_WIFI_UTILS(get_ext_data(platform, ifindex)); \
if (!wifi_data) \
#define WIFI_GET_WIFI_DATA(wifi_data, platform, ifindex, retval) \
NMWifiUtils *wifi_data = get_ext_data_check(platform, ifindex, NM_IS_WIFI_UTILS); \
if (!wifi_data) \
return retval;
#define WIFI_GET_WIFI_DATA_NETNS(wifi_data, platform, ifindex, retval) \
nm_auto_pop_netns NMPNetns *netns = NULL; \
NMWifiUtils *wifi_data; \
if (!nm_platform_netns_push(platform, &netns)) \
return retval; \
wifi_data = get_ext_data_check(platform, ifindex, NM_IS_WIFI_UTILS); \
if (!wifi_data) \
return retval;
static gboolean
@ -9390,9 +9402,9 @@ mesh_set_ssid(NMPlatform *platform, int ifindex, const guint8 *ssid, gsize len)
/*****************************************************************************/
#define WPAN_GET_WPAN_DATA(wpan_data, platform, ifindex, retval) \
NMWpanUtils *wpan_data = NM_WPAN_UTILS(get_ext_data(platform, ifindex)); \
if (!wpan_data) \
#define WPAN_GET_WPAN_DATA(wpan_data, platform, ifindex, retval) \
NMWpanUtils *wpan_data = get_ext_data_check(platform, ifindex, NM_IS_WPAN_UTILS); \
if (!wpan_data) \
return retval;
static guint16
@ -9444,10 +9456,7 @@ link_get_wake_on_lan(NMPlatform *platform, int ifindex)
if (type == NM_LINK_TYPE_ETHERNET)
return nmp_utils_ethtool_get_wake_on_lan(ifindex);
else if (type == NM_LINK_TYPE_WIFI) {
NMWifiUtils *wifi_data = NM_WIFI_UTILS(get_ext_data(platform, ifindex));
if (!wifi_data)
return FALSE;
WIFI_GET_WIFI_DATA(wifi_data, platform, ifindex, FALSE);
return !NM_IN_SET(nm_wifi_utils_get_wake_on_wlan(wifi_data),
_NM_SETTING_WIRELESS_WAKE_ON_WLAN_NONE,