From 0a3835247078bc3cc91b62ce9cd32f0f09485c5e Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Sun, 21 Jun 2015 15:05:52 +0200 Subject: [PATCH] platform: don't assert for valid ifindex in nm_platform_link_get() It's not uncommon to lookup a platform parameter with invalid ifindex or ifname. Be more resilient and just return "no link found". Fixes: e8e455817b340f60b396ba5d41425ed4de4c8554 --- src/platform/nm-platform.c | 25 +++++++++++++------------ 1 file changed, 13 insertions(+), 12 deletions(-) diff --git a/src/platform/nm-platform.c b/src/platform/nm-platform.c index 296d0d6188..e7e0f1052f 100644 --- a/src/platform/nm-platform.c +++ b/src/platform/nm-platform.c @@ -500,9 +500,9 @@ nm_platform_link_get (NMPlatform *self, int ifindex) { _CHECK_SELF (self, klass, NULL); - g_return_val_if_fail (ifindex > 0, NULL); - - return klass->link_get (self, ifindex); + if (ifindex > 0) + return klass->link_get (self, ifindex); + return NULL; } /** @@ -517,9 +517,9 @@ nm_platform_link_get_by_ifname (NMPlatform *self, const char *ifname) { _CHECK_SELF (self, klass, NULL); - g_return_val_if_fail (ifname && *ifname, NULL); - - return klass->link_get_by_ifname (self, ifname); + if (ifname && *ifname) + return klass->link_get_by_ifname (self, ifname); + return NULL; } /** @@ -538,10 +538,13 @@ nm_platform_link_get_by_address (NMPlatform *self, { _CHECK_SELF (self, klass, NULL); - g_return_val_if_fail (address != NULL, NULL); - g_return_val_if_fail (length > 0, NULL); - - return klass->link_get_by_address (self, address, length); + g_return_val_if_fail (length == 0 || address, NULL); + if (length > 0) { + if (length > NM_UTILS_HWADDR_LEN_MAX) + g_return_val_if_reached (NULL); + return klass->link_get_by_address (self, address, length); + } + return NULL; } static NMPlatformError @@ -639,8 +642,6 @@ nm_platform_link_delete (NMPlatform *self, int ifindex) _CHECK_SELF (self, klass, FALSE); - if (ifindex <= 0) - return FALSE; pllink = nm_platform_link_get (self, ifindex); if (!pllink) return FALSE;