RTPS: Fixup our coherent set map.

coherent_set_tracking.coherent_set_registry_map uses a struct as a key,
but the hash and comparison routines treat keys as a sequence of bytes.
Make sure every key byte is initialized. Fixes #16994.

Call wmem_strong_hash on our key in coherent_set_key_hash_by_key instead
of creating and leaking a GBytes struct.


(cherry picked from commit 33e63d19e5)
This commit is contained in:
Gerald Combs 2020-11-09 23:14:18 +00:00
parent d88dc7f29a
commit 6ece1c896d
1 changed files with 8 additions and 10 deletions

View File

@ -1893,6 +1893,8 @@ static void rtps_util_add_coherent_set_general_cases_case(
register_entry);
}
// The hash and compare functions treat the key as a sequence of bytes.
memset(&coherent_set_info_key, 0, sizeof(coherent_set_info_key));
coherent_set_info_key.guid = coherent_set_entity_info_object->guid;
coherent_set_info_key.coherent_set_seq_number = coherent_seq_number;
coherent_set_info_entry = (coherent_set_info*)wmem_map_lookup(coherent_set_tracking.coherent_set_registry_map,
@ -1972,6 +1974,8 @@ static void rtps_util_detect_coherent_set_end_empty_data_case(
coherent_set_info *coherent_set_info_entry;
coherent_set_key key;
// The hash and compare functions treat the key as a sequence of bytes.
memset(&key, 0, sizeof(key));
key.guid = coherent_set_entity_info_object->guid;
key.coherent_set_seq_number = coherent_set_entry->coherent_set_seq_number;
@ -4540,9 +4544,7 @@ static guint hash_by_guid(gconstpointer key) {
return g_int_hash(&(guid->app_id));
}
static gboolean compare_by_guid(gconstpointer a, gconstpointer b) {
const endpoint_guid * guid_a = (const endpoint_guid *) a;
const endpoint_guid * guid_b = (const endpoint_guid *) b;
static gboolean compare_by_guid(gconstpointer guid_a, gconstpointer guid_b) {
return memcmp(guid_a, guid_b, sizeof(endpoint_guid)) == 0;
}
@ -4552,15 +4554,11 @@ static guint get_domain_id_from_tcp_discovered_participants(wmem_map_t *map, end
}
static guint coherent_set_key_hash_by_key(gconstpointer key) {
GBytes * coherent_set_object_key_bytes = NULL;
coherent_set_object_key_bytes = g_bytes_new(key, sizeof(coherent_set_key));
return g_bytes_hash(coherent_set_object_key_bytes);
return wmem_strong_hash((const guint8 *)key, sizeof(coherent_set_key));
}
static gboolean compare_by_coherent_set_key(gconstpointer a, gconstpointer b) {
const coherent_set_key * guid_a = (const coherent_set_key *)a;
const coherent_set_key * guid_b = (const coherent_set_key *)b;
return memcmp(guid_a, guid_b, sizeof(coherent_set_key)) == 0;
static gboolean compare_by_coherent_set_key(gconstpointer key_a, gconstpointer key_b) {
return memcmp(key_a, key_b, sizeof(coherent_set_key)) == 0;
}
static type_mapping * rtps_util_get_topic_info(endpoint_guid * guid) {