mirror of
https://gitlab.freedesktop.org/NetworkManager/NetworkManager.git
synced 2025-12-29 09:10:10 +01:00
platform: fix crash in binary search for _link_type_from_rtnl_type(), _link_type_from_devtype()
When searching an element that is lower than the first list element (for
example RTNL type "batadv"), imax will be -1 after the last iteration.
Use int instead of unsigned to make the termination condition imin > imax
work in this case. This fixes NetworkManager crashing due to an
out-of-bounds array access whenever interfaces of such types exist.
Fixes: 19ad044359 ('platform: use binary search to lookup NMLinkType for rtnl_type')
https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/merge_requests/515
This commit is contained in:
parent
41d431e0f8
commit
2b54202089
1 changed files with 6 additions and 6 deletions
|
|
@ -726,9 +726,9 @@ _link_type_from_rtnl_type (const char *name) \
|
|||
}
|
||||
|
||||
{
|
||||
unsigned imin = 0;
|
||||
unsigned imax = (G_N_ELEMENTS (LIST) - 1);
|
||||
unsigned imid = (G_N_ELEMENTS (LIST) - 1) / 2;
|
||||
int imin = 0;
|
||||
int imax = (G_N_ELEMENTS (LIST) - 1);
|
||||
int imid = (G_N_ELEMENTS (LIST) - 1) / 2;
|
||||
|
||||
for (;;) {
|
||||
const int cmp = strcmp (link_descs[LIST[imid]].rtnl_type, name);
|
||||
|
|
@ -787,9 +787,9 @@ _link_type_from_devtype (const char *name) \
|
|||
}
|
||||
|
||||
{
|
||||
unsigned imin = 0;
|
||||
unsigned imax = (G_N_ELEMENTS (LIST) - 1);
|
||||
unsigned imid = (G_N_ELEMENTS (LIST) - 1) / 2;
|
||||
int imin = 0;
|
||||
int imax = (G_N_ELEMENTS (LIST) - 1);
|
||||
int imid = (G_N_ELEMENTS (LIST) - 1) / 2;
|
||||
|
||||
for (;;) {
|
||||
const int cmp = strcmp (link_descs[LIST[imid]].devtype, name);
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue