diff options
author | Guy Harris <gharris@sonic.net> | 2020-06-21 12:01:07 -0700 |
---|---|---|
committer | Guy Harris <gharris@sonic.net> | 2020-06-21 19:33:19 +0000 |
commit | f97e20a011144a56bf72dd92c49167d17713a909 (patch) | |
tree | 3d167d22778baf2f9800fde1b424f1bf690fc41d /epan/dissectors | |
parent | 4f1276b5fefd548e0dd8e630e3163f144835f6c3 (diff) |
RTPS: don't use incompletely filled in GUIDs.
Add to the GUID type a bitmask that indicates which fields have been
filled in; start it out as 0, and then set bits in it as fields get
filled in.
Do not add a type mapping object to the hash table unless the GUID is
completely filled in, and don't look for a type mapping object in the
hash table with a GUID that hasn't been completely filled in as a key.
Bug: 16642
Change-Id: I31db92238adcb2ec2d70b2650e41b14d99001908
Reviewed-on: https://code.wireshark.org/review/37537
Petri-Dish: Guy Harris <gharris@sonic.net>
Tested-by: Petri Dish Buildbot
Reviewed-by: Guy Harris <gharris@sonic.net>
Diffstat (limited to 'epan/dissectors')
-rw-r--r-- | epan/dissectors/packet-rtps.c | 37 |
1 files changed, 35 insertions, 2 deletions
diff --git a/epan/dissectors/packet-rtps.c b/epan/dissectors/packet-rtps.c index 0a1f964dc6..fbe9f8784c 100644 --- a/epan/dissectors/packet-rtps.c +++ b/epan/dissectors/packet-rtps.c @@ -1643,7 +1643,17 @@ static int* const ENDPOINT_SECURITY_ATTRIBUTES[] = { NULL }; +/* + * Flags indicating which fields have been filled in. + */ +#define GUID_HAS_HOST_ID 0x00000001 +#define GUID_HAS_APP_ID 0x00000002 +#define GUID_HAS_INSTANCE_ID 0x00000004 +#define GUID_HAS_ENTITY_ID 0x00000008 +#define GUID_HAS_ALL 0x0000000F + typedef struct _endpoint_guid { + guint fields_present; guint32 host_id; guint32 app_id; guint32 instance_id; @@ -4411,6 +4421,7 @@ static int rtps_util_add_fragment_number_set(proto_tree *tree, packet_info *pinf static void rtps_util_insert_type_mapping_in_registry(packet_info *pinfo, type_mapping *type_mapping_object) { if (type_mapping_object) { if ((type_mapping_object->fields_visited & TOPIC_INFO_ALL_SET) == TOPIC_INFO_ALL_SET && + type_mapping_object->guid.fields_present == GUID_HAS_ALL && !wmem_map_lookup(registry, &(type_mapping_object->guid))) { if (((type_mapping_object->guid.entity_id & 0x02) == 0x02) || ((type_mapping_object->guid.entity_id & 0x04) == 0x04)){ /* If it is an application defined writer matches 0x02. Matches 0x04 if it is an application defined reader */ @@ -4430,6 +4441,8 @@ static void rtps_util_store_type_mapping(packet_info *pinfo _U_, tvbuff_t *tvb, type_mapping_object->guid.app_id = tvb_get_ntohl(tvb, offset+4); type_mapping_object->guid.instance_id = tvb_get_ntohl(tvb, offset+8); type_mapping_object->guid.entity_id = tvb_get_ntohl(tvb, offset+12); + type_mapping_object->guid.fields_present |= + GUID_HAS_HOST_ID|GUID_HAS_HOST_ID|GUID_HAS_INSTANCE_ID|GUID_HAS_ENTITY_ID; type_mapping_object->fields_visited = type_mapping_object->fields_visited | TOPIC_INFO_ADD_GUID; break; @@ -4455,6 +4468,7 @@ static void rtps_util_store_type_mapping(packet_info *pinfo _U_, tvbuff_t *tvb, static guint hash_by_guid(gconstpointer key) { const endpoint_guid * guid = (const endpoint_guid *) key; + DISSECTOR_ASSERT(guid->fields_present & GUID_HAS_APP_ID); return g_int_hash(&(guid->app_id)); } @@ -4489,8 +4503,10 @@ static gboolean compare_by_coherent_set_key(gconstpointer a, gconstpointer b) { static type_mapping * rtps_util_get_topic_info(endpoint_guid * guid) { /* At this point, we know the boolean enable_topic_info is true */ type_mapping * result = NULL; - if (guid) - result = (type_mapping *)wmem_map_lookup(registry, guid); + if (guid) { + if (guid->fields_present == GUID_HAS_ALL) + result = (type_mapping *)wmem_map_lookup(registry, guid); + } return result; } @@ -4507,6 +4523,7 @@ static void rtps_util_format_typename(gchar * type_name, gchar ** output) { static void rtps_util_topic_info_add_tree(proto_tree *tree, tvbuff_t *tvb, gint offset, endpoint_guid * guid) { + /* Do not search unless the GUID is completely filled in */ if (enable_topic_info) { proto_tree * topic_info_tree; proto_item * ti; @@ -6724,6 +6741,7 @@ static gint dissect_parameter_sequence(proto_tree *tree, packet_info *pinfo, tvb */ type_mapping_object = wmem_new(wmem_file_scope(), type_mapping); type_mapping_object->fields_visited = 0; + type_mapping_object->guid.fields_present = 0; } rtps_parameter_sequence_tree = proto_tree_add_subtree_format(tree, tvb, offset, size, @@ -8140,6 +8158,7 @@ static void dissect_ACKNACK(tvbuff_t *tvb, packet_info *pinfo, gint offset, guin hf_rtps_sm_wrentity_id_kind, ett_rtps_wrentity, "writerEntityId", &wid); offset += 4; guid->entity_id = wid; + guid->fields_present |= GUID_HAS_ENTITY_ID; rtps_util_topic_info_add_tree(tree, tvb, offset, guid); /* Bitmap */ @@ -8312,6 +8331,7 @@ static void dissect_HEARTBEAT(tvbuff_t *tvb, packet_info *pinfo, gint offset, gu hf_rtps_sm_wrentity_id_kind, ett_rtps_wrentity, "writerEntityId", &wid); offset += 4; guid->entity_id = wid; + guid->fields_present |= GUID_HAS_ENTITY_ID; rtps_util_topic_info_add_tree(tree, tvb, offset, guid); /* First available Sequence Number */ @@ -8391,6 +8411,7 @@ static void dissect_HEARTBEAT_BATCH(tvbuff_t *tvb, packet_info *pinfo, gint offs hf_rtps_sm_wrentity_id_kind, ett_rtps_wrentity, "writerEntityId", &wid); offset += 4; guid->entity_id = wid; + guid->fields_present |= GUID_HAS_ENTITY_ID; rtps_util_topic_info_add_tree(tree, tvb, offset, guid); /* First available Batch Sequence Number */ @@ -8532,6 +8553,7 @@ static void dissect_HEARTBEAT_VIRTUAL(tvbuff_t *tvb, packet_info *pinfo _U_, gin writer_id_offset = offset; offset += 4; guid->entity_id = wid; + guid->fields_present |= GUID_HAS_ENTITY_ID; rtps_util_topic_info_add_tree(tree, tvb, offset, guid); /* virtualGUID */ @@ -8733,6 +8755,7 @@ static void dissect_HEARTBEAT_FRAG(tvbuff_t *tvb, packet_info *pinfo, gint offse hf_rtps_sm_wrentity_id_kind, ett_rtps_wrentity, "writerEntityId", &wid); offset += 4; guid->entity_id = wid; + guid->fields_present |= GUID_HAS_ENTITY_ID; rtps_util_topic_info_add_tree(tree, tvb, offset, guid); /* First available Sequence Number */ @@ -8854,6 +8877,7 @@ static void dissect_RTPS_DATA(tvbuff_t *tvb, packet_info *pinfo, gint offset, gu hf_rtps_sm_wrentity_id_kind, ett_rtps_wrentity, "writerEntityId", &wid); offset += 4; guid->entity_id = wid; + guid->fields_present |= GUID_HAS_ENTITY_ID; rtps_util_topic_info_add_tree(tree, tvb, offset, guid); /* Sequence number */ @@ -9188,6 +9212,7 @@ static void dissect_RTPS_DATA_FRAG(tvbuff_t *tvb, packet_info *pinfo, gint offse hf_rtps_sm_wrentity_id_kind, ett_rtps_wrentity, "writerEntityId", &wid); offset += 4; guid->entity_id = wid; + guid->fields_present |= GUID_HAS_ENTITY_ID; rtps_util_topic_info_add_tree(tree, tvb, offset, guid); @@ -9421,6 +9446,7 @@ static void dissect_RTPS_DATA_BATCH(tvbuff_t *tvb, packet_info *pinfo, gint offs hf_rtps_sm_wrentity_id_kind, ett_rtps_wrentity, "writerEntityId", &wid); offset += 4; guid->entity_id = wid; + guid->fields_present |= GUID_HAS_ENTITY_ID; rtps_util_topic_info_add_tree(tree, tvb, offset, guid); @@ -9663,6 +9689,7 @@ static void dissect_GAP(tvbuff_t *tvb, packet_info *pinfo, gint offset, ett_rtps_wrentity, "writerEntityId", &wid); offset += 4; guid->entity_id = wid; + guid->fields_present |= GUID_HAS_ENTITY_ID; rtps_util_topic_info_add_tree(tree, tvb, offset, guid); @@ -9946,6 +9973,7 @@ static void dissect_INFO_DST(tvbuff_t *tvb, packet_info *pinfo, gint offset, gui dst_guid->host_id = tvb_get_ntohl(tvb, offset); dst_guid->app_id = tvb_get_ntohl(tvb, offset + 4); dst_guid->instance_id = tvb_get_ntohl(tvb, offset + 8); + dst_guid->fields_present |= GUID_HAS_HOST_ID|GUID_HAS_APP_ID|GUID_HAS_INSTANCE_ID; } } @@ -10367,6 +10395,10 @@ static gboolean dissect_rtps(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree if ((majorRev != 1) && (majorRev != 2)) return FALSE; + /* No fields have been set in either GUID yet. */ + guid.fields_present = 0; + dst_guid.fields_present = 0; + col_set_str(pinfo->cinfo, COL_PROTOCOL, "RTPS"); col_clear(pinfo->cinfo, COL_INFO); @@ -10397,6 +10429,7 @@ static gboolean dissect_rtps(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree guid.host_id = tvb_get_ntohl(tvb, offset+8); guid.app_id = tvb_get_ntohl(tvb, offset+12); guid.instance_id = tvb_get_ntohl(tvb, offset+16); + guid.fields_present |= GUID_HAS_HOST_ID|GUID_HAS_APP_ID|GUID_HAS_INSTANCE_ID; #ifdef RTI_BUILD pinfo->guid_prefix_host = tvb_get_ntohl(tvb, offset + 8); pinfo->guid_prefix_app = tvb_get_ntohl(tvb, offset + 12); |