aboutsummaryrefslogtreecommitdiffstats
path: root/epan/dissectors/packet-ansi_a.c
diff options
context:
space:
mode:
authorMichael Mann <mmann78@netscape.net>2015-11-27 21:05:32 -0500
committerAnders Broman <a.broman58@gmail.com>2015-11-29 00:02:49 +0000
commitcfc47c15c2b902a50764a21cbcd2ba1d78b1de7a (patch)
tree988ff91986715e3c0d0f317ca25548bce025c369 /epan/dissectors/packet-ansi_a.c
parentefe1b7aa14bd0b3ca9b671fa0d9413124b58adfa (diff)
Replace my_dgt_tbcd_unpack with the safer tvb_bcd_dig_to_wmem_packet_str.
Bug: 11797 Change-Id: I07fdf3f7564424eac053f4c17de17f0d96597cca Reviewed-on: https://code.wireshark.org/review/12239 Petri-Dish: Michael Mann <mmann78@netscape.net> Reviewed-by: Anders Broman <a.broman58@gmail.com>
Diffstat (limited to 'epan/dissectors/packet-ansi_a.c')
-rw-r--r--epan/dissectors/packet-ansi_a.c125
1 files changed, 26 insertions, 99 deletions
diff --git a/epan/dissectors/packet-ansi_a.c b/epan/dissectors/packet-ansi_a.c
index 958530cc5f..cff18d7436 100644
--- a/epan/dissectors/packet-ansi_a.c
+++ b/epan/dissectors/packet-ansi_a.c
@@ -1460,51 +1460,6 @@ static ansi_a_dgt_set_t Dgt_dtmf = {
/* FUNCTIONS */
-/*
- * Unpack BCD input pattern into output ASCII pattern
- *
- * Input Pattern is supplied using the same format as the digits
- *
- * Returns: length of unpacked pattern
- */
-static int
-my_dgt_tbcd_unpack(
- char *out, /* ASCII pattern out */
- guchar *in, /* packed pattern in */
- int num_octs, /* Number of octets to unpack */
- ansi_a_dgt_set_t *dgt /* Digit definitions */
- )
-{
- int cnt = 0;
- unsigned char i;
-
- while (num_octs)
- {
- /*
- * unpack first value in byte
- */
- i = *in++;
- *out++ = dgt->out[i & 0x0f];
- cnt++;
-
- /*
- * unpack second value in byte
- */
- i >>= 4;
-
- if ((num_octs == 1) && (i == 0x0f)) /* odd number bytes - hit filler */
- break;
-
- *out++ = dgt->out[i];
- cnt++;
- num_octs--;
- }
-
- *out = '\0';
-
- return(cnt);
-}
-
static const value_string ansi_a_so_str_vals[] = {
{ 1, "Basic Variable Rate Voice Service (8 kbps)" },
{ 2, "Mobile Station Loopback (8 kbps)" },
@@ -2438,7 +2393,6 @@ static guint8
elem_mid(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, guint32 offset, guint len, ansi_a_shared_data_t *data_p)
{
guint8 oct;
- guint8 *poctets;
guint32 value;
guint32 curr_offset;
const gchar *str;
@@ -2453,23 +2407,16 @@ elem_mid(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, guint32 offset, gu
proto_tree_add_item(tree, hf_ansi_a_meid_mid_digit_1, tvb, curr_offset, 1, ENC_BIG_ENDIAN);
proto_tree_add_item(tree, hf_ansi_a_mid_odd_even_ind, tvb, curr_offset, 1, ENC_BIG_ENDIAN);
proto_tree_add_item(tree, hf_ansi_a_mid_type_of_id, tvb, curr_offset, 1, ENC_BIG_ENDIAN);
-
- a_bigbuf[0] = Dgt_meid.out[(oct & 0xf0) >> 4];
curr_offset++;
- poctets = (guint8 *)tvb_memdup(wmem_packet_scope(), tvb, curr_offset, len - (curr_offset - offset));
+ if (curr_offset - offset >= len) /* Sanity check */
+ return (curr_offset - offset);
- my_dgt_tbcd_unpack(&a_bigbuf[1], poctets, len - (curr_offset - offset),
- &Dgt_meid);
+ str = tvb_bcd_dig_to_wmem_packet_str(tvb, curr_offset, len - (curr_offset - offset), NULL, FALSE);
+ proto_tree_add_string(tree, hf_ansi_a_meid, tvb, curr_offset, len - (curr_offset - offset), str);
+ proto_item_append_text(data_p->elem_item, " - MEID (%s)", str);
curr_offset += len - (curr_offset - offset);
-
- proto_tree_add_string_format_value(tree, hf_ansi_a_meid, tvb, offset + 1, len - 1,
- a_bigbuf,
- "%s",
- a_bigbuf);
-
- proto_item_append_text(data_p->elem_item, " - MEID (%s)", a_bigbuf);
break;
case 2: /* Broadcast Address */
@@ -2542,28 +2489,23 @@ elem_mid(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, guint32 offset, gu
proto_tree_add_item(tree, hf_ansi_a_mid_odd_even_ind, tvb, curr_offset, 1, ENC_BIG_ENDIAN);
proto_tree_add_item(tree, hf_ansi_a_mid_type_of_id, tvb, curr_offset, 1, ENC_BIG_ENDIAN);
-
- a_bigbuf[0] = Dgt_msid.out[(oct & 0xf0) >> 4];
curr_offset++;
- poctets = (guint8 *)tvb_memdup(wmem_packet_scope(), tvb, curr_offset, len - (curr_offset - offset));
-
- my_dgt_tbcd_unpack(&a_bigbuf[1], poctets, len - (curr_offset - offset),
- &Dgt_msid);
+ if (curr_offset - offset >= len) /* Sanity check */
+ return (curr_offset - offset);
- proto_tree_add_string_format(tree, hf_ansi_a_imsi, tvb, curr_offset - 1, len - (curr_offset - 1 - offset),
- a_bigbuf,
- "BCD Digits: %s",
- a_bigbuf);
+ str = tvb_bcd_dig_to_wmem_packet_str(tvb, curr_offset, len - (curr_offset - offset), NULL, FALSE);
+ proto_tree_add_string_format(tree, hf_ansi_a_imsi, tvb, curr_offset, len - (curr_offset - offset),
+ str, "BCD Digits: %s", str);
- proto_item_append_text(data_p->elem_item, " - IMSI (%s)", a_bigbuf);
+ proto_item_append_text(data_p->elem_item, " - IMSI (%s)", str);
if (data_p->message_item)
{
- proto_item_append_text(data_p->message_item, " MID=%s", a_bigbuf);
+ proto_item_append_text(data_p->message_item, " MID=%s", str);
}
if (global_a_info_display)
{
- col_append_fstr(pinfo->cinfo, COL_INFO, "MID=%s ", a_bigbuf);
+ col_append_fstr(pinfo->cinfo, COL_INFO, "MID=%s ", str);
}
curr_offset += len - (curr_offset - offset);
@@ -4111,8 +4053,8 @@ static const value_string ansi_a_cld_party_bcd_num_plan_vals[] = {
static guint8
elem_cld_party_bcd_num(tvbuff_t *tvb, packet_info *pinfo _U_, proto_tree *tree, guint32 offset, guint len, ansi_a_shared_data_t *data_p)
{
- guint8 *poctets;
guint32 curr_offset;
+ const char *str;
curr_offset = offset;
@@ -4122,12 +4064,13 @@ elem_cld_party_bcd_num(tvbuff_t *tvb, packet_info *pinfo _U_, proto_tree *tree,
curr_offset++;
- poctets = (guint8 *)tvb_memdup(wmem_packet_scope(), tvb, curr_offset, len - (curr_offset - offset));
+ if (curr_offset - offset >= len) /* Sanity check */
+ return (curr_offset - offset);
- my_dgt_tbcd_unpack(a_bigbuf, poctets, len - (curr_offset - offset), &Dgt_tbcd);
- proto_tree_add_string(tree, hf_ansi_a_cld_party_bcd_num, tvb, curr_offset, len - (curr_offset - offset), a_bigbuf);
+ str = tvb_bcd_dig_to_wmem_packet_str(tvb, curr_offset, len - (curr_offset - offset), NULL, FALSE);
+ proto_tree_add_string(tree, hf_ansi_a_cld_party_bcd_num, tvb, curr_offset, len - (curr_offset - offset), str);
- proto_item_append_text(data_p->elem_item, " - (%s)", a_bigbuf);
+ proto_item_append_text(data_p->elem_item, " - (%s)", str);
curr_offset += len - (curr_offset - offset);
@@ -7063,39 +7006,23 @@ elem_bdtmf_trans_info(tvbuff_t *tvb, packet_info *pinfo _U_, proto_tree *tree, g
static guint8
elem_dtmf_chars(tvbuff_t *tvb, packet_info *pinfo _U_, proto_tree *tree, guint32 offset, guint len, ansi_a_shared_data_t *data_p)
{
- guint8 oct;
guint32 curr_offset;
guint8 packed_len;
- guint8 *poctets;
+ const char *str;
curr_offset = offset;
proto_tree_add_item(tree, hf_ansi_a_bdtmf_chars_num_chars, tvb, curr_offset, 1, ENC_BIG_ENDIAN);
-
- oct = tvb_get_guint8(tvb, curr_offset);
-
curr_offset++;
- packed_len = len - (curr_offset - offset);
-
- poctets = (guint8 *)tvb_memdup(wmem_packet_scope(), tvb, curr_offset, packed_len);
+ if (curr_offset - offset >= len) /* Sanity check */
+ return (curr_offset - offset);
- /*
- * the packed DTMF digits are not "terminated" with a '0xF' for an odd
- * number of digits but the unpack routine expects it
- */
- if (oct & 0x01)
- {
- poctets[packed_len-1] |= 0xF0;
- }
-
- my_dgt_tbcd_unpack(a_bigbuf, poctets, packed_len,
- &Dgt_dtmf);
-
- proto_tree_add_string(tree, hf_ansi_a_bdtmf_chars_digits, tvb, curr_offset, packed_len,
- a_bigbuf);
+ packed_len = len - (curr_offset - offset);
+ str = tvb_bcd_dig_to_wmem_packet_str(tvb, curr_offset, packed_len, NULL, FALSE);
- proto_item_append_text(data_p->elem_item, " - (%s)", a_bigbuf);
+ proto_tree_add_string(tree, hf_ansi_a_bdtmf_chars_digits, tvb, curr_offset, packed_len, str);
+ proto_item_append_text(data_p->elem_item, " - (%s)", str);
curr_offset += packed_len;