mirror of
https://gitlab.freedesktop.org/NetworkManager/NetworkManager.git
synced 2026-01-21 07:10:37 +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 (cherry picked from commit2b54202089)
This commit is contained in:
parent
30be025e59
commit
8f99116422
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