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 31245cdd62)
This commit is contained in:
Thomas Haller
2018-06-22 15:47:41 +02:00
parent 97de856036
commit df4c62a9c2

View File

@@ -1210,10 +1210,12 @@ nm_manager_get_device_by_ifindex (NMManager *self, int ifindex)
NMManagerPrivate *priv = NM_MANAGER_GET_PRIVATE (self);
NMDevice *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;
}