packet-dccp.c: Don't use tvb_get_ptr for getting a uint number.

Use the tvb_get_ntohXXX instead.

Change-Id: I8d5c6ac2f2c8b1ac9237297f06709513fc2c9113
Reviewed-on: https://code.wireshark.org/review/21733
Reviewed-by: Michael Mann <mmann78@netscape.net>
This commit is contained in:
Michael Mann 2017-05-21 08:12:15 -04:00
parent 8cdbde02c9
commit d4725439c1
1 changed files with 28 additions and 18 deletions

View File

@ -315,24 +315,35 @@ decode_dccp_ports(tvbuff_t *tvb, int offset, packet_info *pinfo,
* a concept by Arnaldo de Melo * a concept by Arnaldo de Melo
*/ */
static guint64 static guint64
tvb_get_ntoh_var(tvbuff_t *tvb, gint offset, guint nbytes) dccp_ntoh_var(tvbuff_t *tvb, gint offset, guint nbytes)
{ {
const guint8 *ptr;
guint64 value = 0; guint64 value = 0;
ptr = tvb_get_ptr(tvb, offset, nbytes); switch (nbytes)
if (nbytes > 5) {
value += ((guint64) * ptr++) << 40; case 5:
if (nbytes > 4) value = tvb_get_ntoh40(tvb, offset);
value += ((guint64) * ptr++) << 32; break;
if (nbytes > 3) case 4:
value += ((guint64) * ptr++) << 24; value = tvb_get_ntohl(tvb, offset);
if (nbytes > 2) break;
value += ((guint64) * ptr++) << 16; case 3:
if (nbytes > 1) value = tvb_get_ntoh24(tvb, offset);
value += ((guint64) * ptr++) << 8; break;
if (nbytes > 0) case 2:
value += *ptr; value = tvb_get_ntohs(tvb, offset);
break;
case 1:
value = tvb_get_guint8(tvb, offset);
break;
case 0:
// do nothing
break;
case 6:
default:
value = tvb_get_ntoh48(tvb, offset);
break;
}
return value; return value;
} }
@ -385,7 +396,7 @@ dissect_feature_options(proto_tree *dccp_options_tree, tvbuff_t *tvb,
if (option_len > 0) /* could be empty Confirm */ if (option_len > 0) /* could be empty Confirm */
proto_item_append_text(dccp_item, " %" G_GINT64_MODIFIER "u", proto_item_append_text(dccp_item, " %" G_GINT64_MODIFIER "u",
tvb_get_ntoh_var(tvb, offset, option_len)); dccp_ntoh_var(tvb, offset, option_len));
break; break;
/* Reserved, specific, or unknown features */ /* Reserved, specific, or unknown features */
@ -469,8 +480,7 @@ dissect_options(tvbuff_t *tvb, packet_info *pinfo,
expert_add_info_format(pinfo, option_item, &ei_dccp_option_len_bad, expert_add_info_format(pinfo, option_item, &ei_dccp_option_len_bad,
"NDP Count too long (max 6 bytes)"); "NDP Count too long (max 6 bytes)");
else else
proto_tree_add_uint64(option_tree, hf_dccp_ndp_count, tvb, offset, option_len, proto_tree_add_item(option_tree, hf_dccp_ndp_count, tvb, offset, option_len, ENC_BIG_ENDIAN);
tvb_get_ntoh_var(tvb, offset, option_len));
break; break;
case 38: case 38:
proto_tree_add_item(option_tree, hf_dccp_ack_vector_nonce_0, tvb, offset, option_len, ENC_NA); proto_tree_add_item(option_tree, hf_dccp_ack_vector_nonce_0, tvb, offset, option_len, ENC_NA);