core: avoid calling platform code with invalid ifindex

Since commit 945c904f95 "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: 945c904f95
This commit is contained in:
Thomas Haller 2018-12-03 13:41:39 +01:00
parent 5fb800125f
commit d45eed4437
3 changed files with 4 additions and 3 deletions

View file

@ -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, \

View file

@ -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) {

View file

@ -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, \