diff options
author | Thomas Haller <thaller@redhat.com> | 2016-02-28 14:37:09 +0100 |
---|---|---|
committer | Thomas Haller <thaller@redhat.com> | 2016-02-29 14:23:22 +0100 |
commit | 06252c9863315d1284507bd9348c809f2e8058f3 (patch) | |
tree | 34f7110a185d4a4a8c7af5ff88980f738d8bb27e | |
parent | c130a3b39a1753294ec6e4da5e254fb389cd6577 (diff) | |
download | NetworkManager-06252c9863315d1284507bd9348c809f2e8058f3.tar.gz |
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.
-rw-r--r-- | src/devices/nm-lldp-listener.c | 10 |
1 files changed, 6 insertions, 4 deletions
diff --git a/src/devices/nm-lldp-listener.c b/src/devices/nm-lldp-listener.c index f57a3068f9..8182781766 100644 --- a/src/devices/nm-lldp-listener.c +++ b/src/devices/nm-lldp-listener.c @@ -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 |