RTPS: avoid errors when encountering empty sequences of strings

Change-Id: Ida9d2e6d632104ec3c6594f5ec500fec49a971a4
Reviewed-on: https://code.wireshark.org/review/19754
Reviewed-by: Michael Mann <mmann78@netscape.net>
Petri-Dish: Michael Mann <mmann78@netscape.net>
Tested-by: Petri Dish Buildbot <buildbot-no-reply@wireshark.org>
Reviewed-by: Anders Broman <a.broman58@gmail.com>
This commit is contained in:
Adam Mitz 2017-01-23 14:15:42 -06:00 committed by Anders Broman
parent 87f24a78e6
commit 4e2b2d4292
2 changed files with 13 additions and 6 deletions

View File

@ -2344,18 +2344,24 @@ static void rtps_util_add_product_version(proto_tree *tree, tvbuff_t *tvb, gint
* Returns the new updated offset
*/
gint rtps_util_add_seq_string(proto_tree *tree, tvbuff_t *tvb, gint offset,
const guint encoding, int param_length, int hf_numstring,
const guint encoding, int hf_numstring,
int hf_string, const char *label) {
guint32 size;
gint32 i, num_strings;
const guint8 *retVal;
proto_tree *string_tree;
gint start;
proto_tree_add_item_ret_int(tree, hf_numstring, tvb, offset, 4, encoding, &num_strings);
offset += 4;
if (num_strings == 0) {
return offset;
}
start = offset;
/* Create the string node with a fake string, the replace it later */
string_tree = proto_tree_add_subtree(tree, tvb, offset, param_length-8, ett_rtps_seq_string, NULL, label);
string_tree = proto_tree_add_subtree(tree, tvb, offset, -1, ett_rtps_seq_string, NULL, label);
for (i = 0; i < num_strings; ++i) {
size = tvb_get_guint32(tvb, offset, encoding);
@ -2368,6 +2374,7 @@ gint rtps_util_add_seq_string(proto_tree *tree, tvbuff_t *tvb, gint offset,
offset += (4 + ((size + 3) & 0xfffffffc));
}
proto_item_set_len(string_tree, offset - start);
return offset;
}
@ -4931,7 +4938,7 @@ static gboolean dissect_parameter_sequence_v1(proto_tree *rtps_parameter_tree, p
case PID_PARTITION:
ENSURE_LENGTH(4);
rtps_util_add_seq_string(rtps_parameter_tree, tvb, offset, encoding,
param_length, hf_rtps_param_partition_num, hf_rtps_param_partition, "name");
hf_rtps_param_partition_num, hf_rtps_param_partition, "name");
break;
/* 0...2...........7...............15.............23...............31
@ -5219,7 +5226,7 @@ static gboolean dissect_parameter_sequence_v1(proto_tree *rtps_parameter_tree, p
temp_offset = rtps_util_add_string(rtps_parameter_tree, tvb, temp_offset,
hf_rtps_param_filter_expression, encoding);
/*temp_offset = */rtps_util_add_seq_string(rtps_parameter_tree, tvb, temp_offset,
encoding, param_length, hf_rtps_param_expression_parameters_num,
encoding, hf_rtps_param_expression_parameters_num,
hf_rtps_param_expression_parameters, "expressionParameters");
break;
}
@ -10825,7 +10832,7 @@ void proto_register_rtps(void) {
},
{ &hf_rtps_param_partition_num,
{ "Size", "rtps.param.partition_num",
{ "Number of partition names", "rtps.param.partition_num",
FT_INT32, BASE_DEC, NULL, 0,
NULL, HFILL }
},

View File

@ -586,7 +586,7 @@ extern void rtps_util_add_durability_service_qos(proto_tree *tree, tvbuff_t * tv
extern void rtps_util_add_liveliness_qos(proto_tree *tree, tvbuff_t * tvb, gint offset,
const guint encoding);
extern gint rtps_util_add_seq_string(proto_tree *tree, tvbuff_t* tvb, gint offset,
const guint encoding, int param_length, int hf_numstring,
const guint encoding, int hf_numstring,
int hf_string, const char *label);
extern gint rtps_util_add_seq_octets(proto_tree *tree, packet_info *pinfo, tvbuff_t* tvb,
gint offset, const guint encoding, int param_length, int hf_id);