From df4c62a9c2bef093137cb152506f0d337fcbf4b6 Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Fri, 22 Jun 2018 15:47:41 +0200 Subject: [PATCH] manager: return NULL for invalid ifindex in nm_manager_get_device_by_ifindex() Internally, the device migth have negative or zero ifindex. When calling nm_manager_get_device_by_ifindex(), the caller wants to find a device with a valid ifindex, hence filter out non-positive values. (cherry picked from commit 31245cdd625966191731fcd795df87f0a10d613f) --- src/nm-manager.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/nm-manager.c b/src/nm-manager.c index 13903d9b6..0fea13de6 100644 --- a/src/nm-manager.c +++ b/src/nm-manager.c @@ -1210,9 +1210,11 @@ nm_manager_get_device_by_ifindex (NMManager *self, int ifindex) NMManagerPrivate *priv = NM_MANAGER_GET_PRIVATE (self); NMDevice *device; - c_list_for_each_entry (device, &priv->devices_lst_head, devices_lst) { - if (nm_device_get_ifindex (device) == ifindex) - return device; + if (ifindex > 0) { + c_list_for_each_entry (device, &priv->devices_lst_head, devices_lst) { + if (nm_device_get_ifindex (device) == ifindex) + return device; + } } return NULL;