diff options
author | Guy Harris <guy@alum.mit.edu> | 2018-06-06 09:22:45 -0700 |
---|---|---|
committer | Guy Harris <guy@alum.mit.edu> | 2018-06-06 16:23:29 +0000 |
commit | f2dada066344924b754ea30569c05adce0c4e9dc (patch) | |
tree | ebd842733faa0d5601821421cb4aec107911874a /epan/expert.c | |
parent | c82883c1d65e0f13478bf4cb14b8f03cf0378988 (diff) |
Make sure proto_tree_add_expert items are always added to the tree.
Make sure that proto_tree_add_text_internal() and
proto_tree_add_text_valist_internal() don't throw an exception, so the
indication always appears in the tree to indicate the issue. Do the
"do the bytes exist" check *after* we've added all of the expert info to
the protocol tree, so we still throw the appropriate exception.
Change-Id: I4e0d2dcc48f9c8f4482550ae16284b9e021232cd
Reviewed-on: https://code.wireshark.org/review/28062
Reviewed-by: Guy Harris <guy@alum.mit.edu>
Diffstat (limited to 'epan/expert.c')
-rw-r--r-- | epan/expert.c | 33 |
1 files changed, 31 insertions, 2 deletions
diff --git a/epan/expert.c b/epan/expert.c index 5538f2a433..32a5d4b27d 100644 --- a/epan/expert.c +++ b/epan/expert.c @@ -622,15 +622,30 @@ proto_tree_add_expert_internal(proto_tree *tree, packet_info *pinfo, expert_fiel { expert_field_info *eiinfo; proto_item *ti; + gint item_length, captured_length; va_list unused; /* Look up the item */ EXPERT_REGISTRAR_GET_NTH(expindex->ei, eiinfo); - ti = proto_tree_add_text_internal(tree, tvb, start, length, "%s", eiinfo->summary); + /* Make sure this doesn't throw an exception when adding the item */ + item_length = length; + captured_length = tvb_captured_length_remaining(tvb, start); + if (captured_length < 0) + item_length = 0; + else if (captured_length < item_length) + item_length = captured_length; + ti = proto_tree_add_text_internal(tree, tvb, start, item_length, "%s", eiinfo->summary); va_start(unused, length); expert_set_info_vformat(pinfo, ti, eiinfo->group, eiinfo->severity, *eiinfo->hf_info.p_id, FALSE, eiinfo->summary, unused); va_end(unused); + + /* But make sure it throws an exception *after* adding the item */ + if (length == -1) { + length = tvb_captured_length(tvb) ? tvb_ensure_captured_length_remaining(tvb, start) : 0; + } else { + tvb_ensure_bytes_exist(tvb, start, length); + } return ti; } @@ -647,19 +662,33 @@ proto_tree_add_expert_format(proto_tree *tree, packet_info *pinfo, expert_field { va_list ap; expert_field_info *eiinfo; + gint item_length, captured_length; proto_item *ti; /* Look up the item */ EXPERT_REGISTRAR_GET_NTH(expindex->ei, eiinfo); + /* Make sure this doesn't throw an exception when adding the item */ + item_length = length; + captured_length = tvb_captured_length_remaining(tvb, start); + if (captured_length < 0) + item_length = 0; + else if (captured_length < item_length) + item_length = captured_length; va_start(ap, format); - ti = proto_tree_add_text_valist_internal(tree, tvb, start, length, format, ap); + ti = proto_tree_add_text_valist_internal(tree, tvb, start, item_length, format, ap); va_end(ap); va_start(ap, format); expert_set_info_vformat(pinfo, ti, eiinfo->group, eiinfo->severity, *eiinfo->hf_info.p_id, TRUE, format, ap); va_end(ap); + /* But make sure it throws an exception *after* adding the item */ + if (length == -1) { + length = tvb_captured_length(tvb) ? tvb_ensure_captured_length_remaining(tvb, start) : 0; + } else { + tvb_ensure_bytes_exist(tvb, start, length); + } return ti; } |