From 9dc332454aa50e62e68d854cb03eee615b8999f1 Mon Sep 17 00:00:00 2001 From: Bill Meier Date: Tue, 5 Aug 2014 12:35:36 -0400 Subject: Various minor dissector fixes/changes - Fix a few minor bugs; - Remove unneeded #includes; - Do some whitespace/long_lines formatting changes. Change-Id: I97239fa20727498604682239cda0e1b87b10f4bc Reviewed-on: https://code.wireshark.org/review/3434 Petri-Dish: Bill Meier Reviewed-by: Bill Meier --- epan/dissectors/packet-bencode.c | 153 +++++++++++++++++++++------------------ 1 file changed, 84 insertions(+), 69 deletions(-) (limited to 'epan/dissectors/packet-bencode.c') diff --git a/epan/dissectors/packet-bencode.c b/epan/dissectors/packet-bencode.c index 7ce5855951..e85bb6dd31 100644 --- a/epan/dissectors/packet-bencode.c +++ b/epan/dissectors/packet-bencode.c @@ -26,8 +26,6 @@ #include "config.h" #include -#include -#include #include #include #include @@ -36,25 +34,25 @@ void proto_register_bencode(void); static int proto_bencode = -1; -static gint hf_bencode_str_length = -1; -static gint hf_bencode_str = -1; -static gint hf_bencode_int = -1; -static gint hf_bencode_dict = -1; -static gint hf_bencode_dict_entry = -1; -static gint hf_bencode_list = -1; +static gint hf_bencode_str_length = -1; +static gint hf_bencode_str = -1; +static gint hf_bencode_int = -1; +static gint hf_bencode_dict = -1; +static gint hf_bencode_dict_entry = -1; +static gint hf_bencode_list = -1; static gint hf_bencode_truncated_data = -1; static gint ett_bencode_dict = -1; static gint ett_bencode_dict_entry = -1; static gint ett_bencode_list = -1; -static expert_field ei_bencode_str = EI_INIT; +static expert_field ei_bencode_str = EI_INIT; static expert_field ei_bencode_str_length = EI_INIT; -static expert_field ei_bencode_int = EI_INIT; -static expert_field ei_bencode_nest = EI_INIT; -static expert_field ei_bencode_dict_key = EI_INIT; +static expert_field ei_bencode_int = EI_INIT; +static expert_field ei_bencode_nest = EI_INIT; +static expert_field ei_bencode_dict_key = EI_INIT; static expert_field ei_bencode_dict_value = EI_INIT; -static expert_field ei_bencode_invalid = EI_INIT; +static expert_field ei_bencode_invalid = EI_INIT; static int dissect_bencoding_str(tvbuff_t *tvb, packet_info *pinfo, int offset, int length, proto_tree *tree, proto_item *ti, int treeadd) @@ -64,44 +62,48 @@ static int dissect_bencoding_str(tvbuff_t *tvb, packet_info *pinfo, int used; int izero = 0; - if (length<2) { + if (length < 2) { proto_tree_add_expert(tree, pinfo, &ei_bencode_str, tvb, offset, length); return -1; } used = 0; - while (length>=1) { - ch = tvb_get_guint8(tvb, offset+used); + while (length >= 1) { + ch = tvb_get_guint8(tvb, offset + used); length--; used++; - if (ch==':' && used>1) { - if (stringlen>length || stringlen<0) { + if ((ch == ':') && (used > 1)) { + if ((stringlen > length) || (stringlen < 0)) { proto_tree_add_expert(tree, pinfo, &ei_bencode_str_length, tvb, offset, length); return -1; } if (tree) { proto_tree_add_uint(tree, hf_bencode_str_length, tvb, offset, used, stringlen); - proto_tree_add_item(tree, hf_bencode_str, tvb, offset+used, stringlen, ENC_ASCII|ENC_NA); + proto_tree_add_item(tree, hf_bencode_str, tvb, offset + used, stringlen, ENC_ASCII|ENC_NA); - if (treeadd==1) { - proto_item_append_text(ti, " Key: %s", format_text((guchar *)tvb_memdup(wmem_packet_scope(), tvb, offset+used, stringlen), stringlen)); + if (treeadd == 1) { + proto_item_append_text(ti, " Key: %s", + format_text((guchar *)tvb_memdup(wmem_packet_scope(), + tvb, offset + used, stringlen), stringlen)); } - if (treeadd==2) { - proto_item_append_text(ti, " Value: %s", format_text((guchar *)tvb_memdup(wmem_packet_scope(), tvb, offset+used, stringlen), stringlen)); + if (treeadd == 2) { + proto_item_append_text(ti, " Value: %s", + format_text((guchar *)tvb_memdup(wmem_packet_scope(), + tvb, offset + used, stringlen), stringlen)); } } - return used+stringlen; + return used + stringlen; } - if (!izero && ch>='0' && ch<='9') { - if (ch=='0' && used==1) { + if (!izero && (ch >= '0') && (ch <= '9')) { + if ((ch == '0') && (used == 1)) { izero = 1; } nextstringlen = (stringlen * 10) + (ch - '0'); - if (nextstringlen>=stringlen) { + if (nextstringlen >= stringlen) { stringlen = nextstringlen; continue; } @@ -118,10 +120,10 @@ static int dissect_bencoding_str(tvbuff_t *tvb, packet_info *pinfo, static int dissect_bencoding_int(tvbuff_t *tvb, packet_info *pinfo _U_, int offset, int length, proto_tree *tree, proto_item *ti, int treeadd) { - gint32 ival=0; - int neg = 0; - int izero = 0; - int used; + gint32 ival = 0; + int neg = 0; + int izero = 0; + int used; guint8 ch; if (length<3) { @@ -132,8 +134,8 @@ static int dissect_bencoding_int(tvbuff_t *tvb, packet_info *pinfo _U_, length--; used = 1; - while (length>=1) { - ch = tvb_get_guint8(tvb, offset+used); + while (length >= 1) { + ch = tvb_get_guint8(tvb, offset + used); length--; used++; @@ -142,26 +144,26 @@ static int dissect_bencoding_int(tvbuff_t *tvb, packet_info *pinfo _U_, if (tree) { if (neg) ival = -ival; proto_tree_add_int(tree, hf_bencode_int, tvb, offset, used, ival); - if (treeadd==2) { + if (treeadd == 2) { proto_item_append_text(ti, " Value: %d", ival); } } return used; case '-': - if (used==2) { + if (used == 2) { neg = 1; break; } /* Fall through */ default: - if (!(ch=='0' && used==3 && neg)) { /* -0 is invalid */ - if (ch=='0' && used==2) { /* as is 0[0-9]+ */ + if (!((ch == '0') && (used == 3) && neg)) { /* -0 is invalid */ + if ((ch == '0') && (used == 2)) { /* as is 0[0-9]+ */ izero = 1; break; } - if (!izero && ch>='0' && ch<='9') { + if (!izero && (ch >= '0') && (ch <= '9')) { ival = (ival * 10) + (ch - '0'); break; } @@ -186,18 +188,18 @@ static int dissect_bencoding_rec(tvbuff_t *tvb, packet_info *pinfo _U_, proto_item *ti = NULL, *td = NULL; proto_tree *itree = NULL, *dtree = NULL; - if (level>10) { + if (level > 10) { proto_tree_add_expert(tree, pinfo, &ei_bencode_nest, tvb, offset, -1); return -1; } - if (length<1) { + if (length < 1) { proto_tree_add_item(tree, hf_bencode_truncated_data, tvb, offset, -1, ENC_NA); return length; } op = tvb_get_guint8(tvb, offset); - oplen = dissect_bencoding_rec(tvb, pinfo, offset, length, NULL, level+1, NULL, 0); - if (oplen<0) + oplen = dissect_bencoding_rec(tvb, pinfo, offset, length, NULL, level + 1, NULL, 0); + if (oplen < 0) oplen = length; switch (op) { @@ -208,38 +210,38 @@ static int dissect_bencoding_rec(tvbuff_t *tvb, packet_info *pinfo _U_, used = 1; length--; - while (length>=1) { - op = tvb_get_guint8(tvb, offset+used); + while (length >= 1) { + op = tvb_get_guint8(tvb, offset + used); - if (op=='e') { - return used+1; + if (op == 'e') { + return used + 1; } - op1len = dissect_bencoding_str(tvb, pinfo, offset+used, length, NULL, NULL, 0); - if (op1len<0) { - proto_tree_add_expert(dtree, pinfo, &ei_bencode_dict_key, tvb, offset+used, -1); + op1len = dissect_bencoding_str(tvb, pinfo, offset + used, length, NULL, NULL, 0); + if (op1len < 0) { + proto_tree_add_expert(dtree, pinfo, &ei_bencode_dict_key, tvb, offset + used, -1); return op1len; } op2len = -1; - if (length-op1len>2) - op2len = dissect_bencoding_rec(tvb, pinfo, offset+used+op1len, length-op1len, NULL, level+1, NULL, 0); - if (op2len<0) { - proto_tree_add_expert(dtree, pinfo, &ei_bencode_dict_value, tvb, offset+used+op1len, -1); + if ((length - op1len) > 2) + op2len = dissect_bencoding_rec(tvb, pinfo, offset + used + op1len, length - op1len, NULL, level + 1, NULL, 0); + if (op2len < 0) { + proto_tree_add_expert(dtree, pinfo, &ei_bencode_dict_value, tvb, offset + used + op1len, -1); return op2len; } - ti = proto_tree_add_item(dtree, hf_bencode_dict_entry, tvb, offset+used, op1len+op2len, ENC_NA); + ti = proto_tree_add_item(dtree, hf_bencode_dict_entry, tvb, offset + used, op1len + op2len, ENC_NA); itree = proto_item_add_subtree(ti, ett_bencode_dict_entry); - dissect_bencoding_str(tvb, pinfo, offset+used, length, itree, ti, 1); - dissect_bencoding_rec(tvb, pinfo, offset+used+op1len, length-op1len, itree, level+1, ti, 2); + dissect_bencoding_str(tvb, pinfo, offset + used, length, itree, ti, 1); + dissect_bencoding_rec(tvb, pinfo, offset + used + op1len, length - op1len, itree, level + 1, ti, 2); - used += op1len+op2len; - length -= op1len+op2len; + used += op1len + op2len; + length -= op1len + op2len; } - proto_tree_add_item(dtree, hf_bencode_truncated_data, tvb, offset+used, -1, ENC_NA); + proto_tree_add_item(dtree, hf_bencode_truncated_data, tvb, offset + used, -1, ENC_NA); return -1; case 'l': @@ -249,28 +251,28 @@ static int dissect_bencoding_rec(tvbuff_t *tvb, packet_info *pinfo _U_, used = 1; length--; - while (length>=1) { - op = tvb_get_guint8(tvb, offset+used); + while (length >= 1) { + op = tvb_get_guint8(tvb, offset + used); - if (op=='e') { - return used+1; + if (op == 'e') { + return used + 1; } - oplen = dissect_bencoding_rec(tvb, pinfo, offset+used, length, itree, level+1, ti, 0); - if (oplen<1) return oplen; + oplen = dissect_bencoding_rec(tvb, pinfo, offset + used, length, itree, level + 1, ti, 0); + if (oplen < 1) return oplen; - used += oplen; + used += oplen; length -= oplen; } - proto_tree_add_item(itree, hf_bencode_truncated_data, tvb, offset+used, -1, ENC_NA); + proto_tree_add_item(itree, hf_bencode_truncated_data, tvb, offset + used, -1, ENC_NA); return -1; case 'i': return dissect_bencoding_int(tvb, pinfo, offset, length, tree, treei, treeadd); default: - if (op>='1' && op<='9') { + if ((op >= '1') && (op <= '9')) { return dissect_bencoding_str(tvb, pinfo, offset, length, tree, treei, treeadd); } @@ -282,7 +284,7 @@ static int dissect_bencoding_rec(tvbuff_t *tvb, packet_info *pinfo _U_, static void dissect_bencoding(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree) { - dissect_bencoding_rec(tvb, pinfo, 0, tvb_length(tvb), tree, 0, NULL, 0); + dissect_bencoding_rec(tvb, pinfo, 0, tvb_reported_length(tvb), tree, 0, NULL, 0); } void @@ -337,3 +339,16 @@ proto_register_bencode(void) expert_bencode = expert_register_protocol(proto_bencode); expert_register_field_array(expert_bencode, ei, array_length(ei)); } + +/* + * Editor modelines - http://www.wireshark.org/tools/modelines.html + * + * Local variables: + * c-basic-offset: 3 + * tab-width: 8 + * indent-tabs-mode: nil + * End: + * + * vi: set shiftwidth=3 tabstop=8 expandtab: + * :indentSize=3:tabSize=8:noTabs=true: + */ -- cgit v1.2.3