libnm: fix bounds check in _get_mac_blacklist_item()

The bounds checks are incorrect, as we cannot access the array at `idx == len`.

https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/merge_requests/1767
Fixes: dfcb221337 ('libnm-core: make _get_mac_address_blacklist() methods return arrays')
(cherry picked from commit 94fd9aed1e)
This commit is contained in:
Jan Vaclav 2023-10-19 14:58:10 +02:00 committed by Thomas Haller
parent 7713f4e90a
commit 1b98e30927
No known key found for this signature in database
GPG key ID: 29C2366E4DFC5728
2 changed files with 12 additions and 2 deletions

View file

@ -325,7 +325,12 @@ nm_setting_wired_get_mac_blacklist_item(NMSettingWired *setting, guint32 idx)
g_return_val_if_fail(NM_IS_SETTING_WIRED(setting), NULL);
priv = NM_SETTING_WIRED_GET_PRIVATE(setting);
g_return_val_if_fail(idx <= priv->mac_address_blacklist->len, NULL);
if (idx == priv->mac_address_blacklist->len) {
return NULL;
}
g_return_val_if_fail(idx < priv->mac_address_blacklist->len, NULL);
return nm_g_array_index(priv->mac_address_blacklist, const char *, idx);
}

View file

@ -510,7 +510,12 @@ nm_setting_wireless_get_mac_blacklist_item(NMSettingWireless *setting, guint32 i
g_return_val_if_fail(NM_IS_SETTING_WIRELESS(setting), NULL);
priv = NM_SETTING_WIRELESS_GET_PRIVATE(setting);
g_return_val_if_fail(idx <= priv->mac_address_blacklist->len, NULL);
if (idx == priv->mac_address_blacklist->len) {
return NULL;
}
g_return_val_if_fail(idx < priv->mac_address_blacklist->len, NULL);
return nm_g_array_index(priv->mac_address_blacklist, const char *, idx);
}