mirror of
https://gitlab.freedesktop.org/NetworkManager/NetworkManager.git
synced 2026-02-05 05:20:32 +01:00
lldp: handle NULL values in lldp_neighbor_id_hash()
g_str_hash() can not be called with NULL. Ensure that we don't crash. Thereby, refactor the hashing algorithm because the chassis-id and port-id are small numbers and xor-ing can cancel them easily.
This commit is contained in:
parent
c130a3b39a
commit
06252c9863
1 changed files with 6 additions and 4 deletions
|
|
@ -126,11 +126,13 @@ static guint
|
|||
lldp_neighbor_id_hash (gconstpointer ptr)
|
||||
{
|
||||
const LLDPNeighbor *neigh = ptr;
|
||||
guint hash;
|
||||
|
||||
return g_str_hash (neigh->chassis_id) ^
|
||||
g_str_hash (neigh->port_id) ^
|
||||
neigh->chassis_id_type ^
|
||||
(neigh->port_id_type * 33);
|
||||
hash = 23423423u + ((guint) (neigh->chassis_id ? g_str_hash (neigh->chassis_id) : 12321u));
|
||||
hash = (hash * 33u) + ((guint) (neigh->port_id ? g_str_hash (neigh->port_id) : 34342343u));
|
||||
hash = (hash * 33u) + ((guint) neigh->chassis_id_type);
|
||||
hash = (hash * 33u) + ((guint) neigh->port_id_type);
|
||||
return hash;
|
||||
}
|
||||
|
||||
static gboolean
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue