From d45eed4437fda2bf84a4e5023d99873c42cadf84 Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Mon, 3 Dec 2018 13:41:39 +0100 Subject: [PATCH] core: avoid calling platform code with invalid ifindex Since commit 945c904f956 "platform: assert against valid ifindex and remove duplicate assertions", it is no longer allowed to call certain platform functions with invalid ifindex. These trigger now an assertion. Note that the assertion is merely a g_return_val_if_fail(), hence in non-debug mode, this does not lead to a crash. Fixes: 945c904f956580616f0d71b13c63f525c184060c --- src/devices/nm-acd-manager.c | 2 +- src/devices/nm-device.c | 3 ++- src/devices/nm-lldp-listener.c | 2 +- 3 files changed, 4 insertions(+), 3 deletions(-) diff --git a/src/devices/nm-acd-manager.c b/src/devices/nm-acd-manager.c index 42dff5379a..7be0374baa 100644 --- a/src/devices/nm-acd-manager.c +++ b/src/devices/nm-acd-manager.c @@ -65,7 +65,7 @@ struct _NMAcdManager { char _sbuf[64]; \ \ nm_log ((level), _NMLOG_DOMAIN, \ - self ? nm_platform_link_get_name (NM_PLATFORM_GET, self->ifindex) : "", \ + self && self->ifindex > 0 ? nm_platform_link_get_name (NM_PLATFORM_GET, self->ifindex) : NULL, \ NULL, \ "%s%s: " _NM_UTILS_MACRO_FIRST (__VA_ARGS__), \ _NMLOG_PREFIX_NAME, \ diff --git a/src/devices/nm-device.c b/src/devices/nm-device.c index c2223a9850..3e48f2005a 100644 --- a/src/devices/nm-device.c +++ b/src/devices/nm-device.c @@ -4846,7 +4846,8 @@ nm_device_master_release_slaves (NMDevice *self) if (priv->state == NM_DEVICE_STATE_FAILED) reason = NM_DEVICE_STATE_REASON_DEPENDENCY_FAILED; - if (!nm_platform_link_get (nm_device_get_platform (self), priv->ifindex)) + if ( priv->ifindex <= 0 + || !nm_platform_link_get (nm_device_get_platform (self), priv->ifindex)) configure = FALSE; c_list_for_each_safe (iter, safe, &priv->slaves) { diff --git a/src/devices/nm-lldp-listener.c b/src/devices/nm-lldp-listener.c index c0484ed30a..ae18063709 100644 --- a/src/devices/nm-lldp-listener.c +++ b/src/devices/nm-lldp-listener.c @@ -128,7 +128,7 @@ typedef struct { int _ifindex = (self) ? NM_LLDP_LISTENER_GET_PRIVATE (self)->ifindex : 0; \ \ _nm_log (_level, _NMLOG_DOMAIN, 0, \ - nm_platform_link_get_name (NM_PLATFORM_GET, _ifindex), \ + _ifindex > 0 ? nm_platform_link_get_name (NM_PLATFORM_GET, _ifindex) : NULL, \ NULL, \ "%s%s: " _NM_UTILS_MACRO_FIRST (__VA_ARGS__), \ _NMLOG_PREFIX_NAME, \