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

View File

@@ -9213,15 +9213,27 @@ get_ext_data(NMPlatform *platform, int ifindex)
return obj->_link.ext_data; 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) \ #define WIFI_GET_WIFI_DATA(wifi_data, platform, ifindex, retval) \
nm_auto_pop_netns NMPNetns *netns = NULL; \ NMWifiUtils *wifi_data = get_ext_data_check(platform, ifindex, NM_IS_WIFI_UTILS); \
NMWifiUtils *wifi_data; \ if (!wifi_data) \
if (!nm_platform_netns_push(platform, &netns)) \ return retval;
return retval; \
wifi_data = NM_WIFI_UTILS(get_ext_data(platform, ifindex)); \ #define WIFI_GET_WIFI_DATA_NETNS(wifi_data, platform, ifindex, retval) \
if (!wifi_data) \ 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; return retval;
static gboolean 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) \ #define WPAN_GET_WPAN_DATA(wpan_data, platform, ifindex, retval) \
NMWpanUtils *wpan_data = NM_WPAN_UTILS(get_ext_data(platform, ifindex)); \ NMWpanUtils *wpan_data = get_ext_data_check(platform, ifindex, NM_IS_WPAN_UTILS); \
if (!wpan_data) \ if (!wpan_data) \
return retval; return retval;
static guint16 static guint16
@@ -9444,10 +9456,7 @@ link_get_wake_on_lan(NMPlatform *platform, int ifindex)
if (type == NM_LINK_TYPE_ETHERNET) if (type == NM_LINK_TYPE_ETHERNET)
return nmp_utils_ethtool_get_wake_on_lan(ifindex); return nmp_utils_ethtool_get_wake_on_lan(ifindex);
else if (type == NM_LINK_TYPE_WIFI) { else if (type == NM_LINK_TYPE_WIFI) {
NMWifiUtils *wifi_data = NM_WIFI_UTILS(get_ext_data(platform, ifindex)); WIFI_GET_WIFI_DATA(wifi_data, platform, ifindex, FALSE);
if (!wifi_data)
return FALSE;
return !NM_IN_SET(nm_wifi_utils_get_wake_on_wlan(wifi_data), return !NM_IN_SET(nm_wifi_utils_get_wake_on_wlan(wifi_data),
_NM_SETTING_WIRELESS_WAKE_ON_WLAN_NONE, _NM_SETTING_WIRELESS_WAKE_ON_WLAN_NONE,