3
0
mirror of https://git.kernel.org/pub/scm/network/wireless/iwd.git synced 2024-12-22 04:32:37 +01:00

treewide: guard compare functions against signed integer overflow

Besides being undefined behaviour, signed integer overflow can cause
unexpected comparison results. In the case of network_rank_compare(),
a connected network with rank INT_MAX would cause newly inserted
networks with negative rank to be inserted earlier in the ordered
network list. This is reflected in the GetOrderedMethods() DBus method
as can be seen in the following iwctl output:

  [iwd]# station wlan0 get-networks
    Network name                    Security  Signal
  ----------------------------------------------------
    BEOLAN                          8021x     **** }
    BeoBlue                         psk       ***  } all unknown,
    UI_Test_Network                 psk       ***  } hence assigned
    deneb_2G                        psk       ***  } negative rank
    BEOGUEST                        open      **** }
  > titan                           psk       ****
    Linksys05274_5GHz_dmt           psk       ****
    Lyngby-4G-4 5GHz                psk       ****
This commit is contained in:
Alvin Šipraga 2020-08-14 15:40:33 +02:00 committed by Denis Kenzior
parent 94d4b341e3
commit bfd8cead95
4 changed files with 5 additions and 5 deletions

View File

@ -1380,7 +1380,7 @@ int network_rank_compare(const void *a, const void *b, void *user)
const struct network *new_network = a;
const struct network *network = b;
return network->rank - new_network->rank;
return (network->rank > new_network->rank) ? 1 : -1;
}
void network_rank_update(struct network *network, bool connected)

View File

@ -1436,7 +1436,7 @@ int scan_bss_rank_compare(const void *a, const void *b, void *user_data)
{
const struct scan_bss *new_bss = a, *bss = b;
return bss->rank - new_bss->rank;
return (bss->rank > new_bss->rank) ? 1 : -1;
}
static void get_scan_callback(struct l_genl_msg *msg, void *user_data)

View File

@ -196,7 +196,7 @@ static int autoconnect_rank_compare(const void *a, const void *b, void *user)
const struct autoconnect_entry *new_ae = a;
const struct autoconnect_entry *ae = b;
return ae->rank - new_ae->rank;
return (ae->rank > new_ae->rank) ? 1 : -1;
}
static void station_add_autoconnect_bss(struct station *station,
@ -290,7 +290,7 @@ static int bss_signal_strength_compare(const void *a, const void *b, void *user)
const struct scan_bss *new_bss = a;
const struct scan_bss *bss = b;
return bss->signal_strength - new_bss->signal_strength;
return (bss->signal_strength > new_bss->signal_strength) ? 1 : -1;
}
/*

View File

@ -1867,7 +1867,7 @@ static int rule_compare_priority(const void *a, const void *b, void *user)
const struct hwsim_rule *rule_a = a;
const struct hwsim_rule *rule_b = b;
return rule_a->priority - rule_b->priority;
return (rule_a->priority > rule_b->priority) ? 1 : -1;
}
static struct l_dbus_message *rule_add(struct l_dbus *dbus,