aboutsummaryrefslogtreecommitdiffstats
path: root/epan/dissectors/packet-bzr.c
diff options
context:
space:
mode:
authorGuy Harris <guy@alum.mit.edu>2018-06-12 10:47:36 -0700
committerGuy Harris <guy@alum.mit.edu>2018-06-12 17:49:59 +0000
commita03eacc7aabd04a6fd0db978e0d7597220ac0515 (patch)
treeb3cec1ef6e62e720ebe823c9e3eabb64ea4965d7 /epan/dissectors/packet-bzr.c
parent362576e107a5d0b4aaf17e2009c6dc43ea9a9d13 (diff)
Clean up handling of counted blobs of bytes.
Don't treat the count+blob as itself a blob of bytes; use FT_NONE. Create it with an unknown length (-1, meaning "to end of packet, for now"), and set its length once we've finished dissecting it. Dissect the raw bytes of a prefixed-bytes item regardless of whether we're building a protocol tree or not. This means we do a better job of handling a too-large length; instead of overflowing the offset, we throw an exception and stop dissecting, so we don't run the risk of looping infinitely. Bug: 14841 Change-Id: I593be9b6ba9aa15d8529f96458e53b85ace6402a Reviewed-on: https://code.wireshark.org/review/28228 Reviewed-by: Guy Harris <guy@alum.mit.edu>
Diffstat (limited to 'epan/dissectors/packet-bzr.c')
-rw-r--r--epan/dissectors/packet-bzr.c28
1 files changed, 14 insertions, 14 deletions
diff --git a/epan/dissectors/packet-bzr.c b/epan/dissectors/packet-bzr.c
index 5b2a29fe9a..53ded8d5fa 100644
--- a/epan/dissectors/packet-bzr.c
+++ b/epan/dissectors/packet-bzr.c
@@ -125,16 +125,18 @@ dissect_prefixed_bencode(tvbuff_t *tvb, gint offset, packet_info *pinfo,
plen = tvb_get_ntohl(tvb, offset);
- ti = proto_tree_add_item(tree, hf_bzr_prefixed_bencode, tvb, offset, 4 +
- plen, ENC_NA);
+ ti = proto_tree_add_item(tree, hf_bzr_prefixed_bencode, tvb, offset, -1,
+ ENC_NA);
prefixed_bencode_tree = proto_item_add_subtree(ti, ett_prefixed_bencode);
proto_tree_add_item(prefixed_bencode_tree, hf_bzr_prefixed_bencode_len,
- tvb, offset, 4, ENC_BIG_ENDIAN);
+ tvb, offset, 4, ENC_BIG_ENDIAN);
subtvb = tvb_new_subset_length(tvb, offset+4, plen);
call_dissector(bencode_handle, subtvb, pinfo, prefixed_bencode_tree);
+ proto_item_set_len(ti, 4 + plen);
+
return 4 + plen;
}
@@ -148,18 +150,16 @@ dissect_prefixed_bytes(tvbuff_t *tvb, gint offset, packet_info *pinfo _U_,
plen = tvb_get_ntohl(tvb, offset);
- ti = proto_tree_add_item(tree, hf_bzr_bytes, tvb, offset, 4 +
- plen, ENC_NA);
+ ti = proto_tree_add_item(tree, hf_bzr_bytes, tvb, offset, -1, ENC_NA);
prefixed_bytes_tree = proto_item_add_subtree(ti, ett_prefixed_bytes);
- if (prefixed_bytes_tree)
- {
- proto_tree_add_item(prefixed_bytes_tree, hf_bzr_bytes_length,
- tvb, offset, 4, ENC_BIG_ENDIAN);
+ proto_tree_add_item(prefixed_bytes_tree, hf_bzr_bytes_length,
+ tvb, offset, 4, ENC_BIG_ENDIAN);
- proto_tree_add_item(prefixed_bytes_tree, hf_bzr_bytes_data,
- tvb, offset+4, plen, ENC_NA);
- }
+ proto_tree_add_item(prefixed_bytes_tree, hf_bzr_bytes_data,
+ tvb, offset+4, plen, ENC_NA);
+
+ proto_item_set_len(ti, 4 + plen);
return 4 + plen;
}
@@ -261,7 +261,7 @@ proto_register_bzr(void)
NULL, 0x0, NULL, HFILL },
},
{ &hf_bzr_prefixed_bencode,
- { "Bencode packet", "bzr.bencode", FT_BYTES, BASE_NONE, NULL, 0x0,
+ { "Bencode packet", "bzr.bencode", FT_NONE, BASE_NONE, NULL, 0x0,
"Serialized structure of integers, dictionaries, strings and "
"lists.", HFILL },
},
@@ -270,7 +270,7 @@ proto_register_bzr(void)
BASE_HEX, NULL, 0x0, NULL, HFILL },
},
{ &hf_bzr_bytes,
- { "Prefixed bytes", "bzr.bytes", FT_BYTES, BASE_NONE, NULL, 0x0,
+ { "Prefixed bytes", "bzr.bytes", FT_NONE, BASE_NONE, NULL, 0x0,
"Bytes field with prefixed 32-bit length", HFILL },
},
{ &hf_bzr_bytes_data,