diff options
author | Michael Mann <mmann78@netscape.net> | 2015-01-07 08:29:35 -0500 |
---|---|---|
committer | Michael Mann <mmann78@netscape.net> | 2015-01-07 18:05:35 +0000 |
commit | 9cfe67fde61fa16cdf433cb152b5b22949648c64 (patch) | |
tree | 5f61b4cf38f1c1d90f73d90092de65194be60adb /epan | |
parent | 493f03b4200f96f45fadf3302b1d3bfb5a95b409 (diff) |
tvb_bytes_to_ep_str_punct -> tvb_bytes_to_str_punct
Also change bytestring_to_str to match bytes_to_ep_str_punct functionality (limiting byte string size)
Change-Id: Idb958c7f0c203d103629469302b81fa922714f7e
Reviewed-on: https://code.wireshark.org/review/6369
Reviewed-by: Michael Mann <mmann78@netscape.net>
Diffstat (limited to 'epan')
-rw-r--r-- | epan/dissectors/packet-coap.c | 4 | ||||
-rw-r--r-- | epan/dissectors/packet-devicenet.c | 12 | ||||
-rw-r--r-- | epan/dissectors/packet-dhcpv6.c | 4 | ||||
-rw-r--r-- | epan/dissectors/packet-fcsb3.c | 2 | ||||
-rw-r--r-- | epan/dissectors/packet-fip.c | 4 | ||||
-rw-r--r-- | epan/dissectors/packet-ismacryp.c | 6 | ||||
-rw-r--r-- | epan/dissectors/packet-j1939.c | 2 | ||||
-rw-r--r-- | epan/dissectors/packet-netflow.c | 4 | ||||
-rw-r--r-- | epan/dissectors/packet-opensafety.c | 4 | ||||
-rw-r--r-- | epan/dissectors/packet-socketcan.c | 2 | ||||
-rw-r--r-- | epan/dissectors/packet-zbee-zcl.c | 4 | ||||
-rw-r--r-- | epan/to_str.c | 34 | ||||
-rw-r--r-- | epan/tvbuff.c | 4 | ||||
-rw-r--r-- | epan/tvbuff.h | 2 |
14 files changed, 47 insertions, 41 deletions
diff --git a/epan/dissectors/packet-coap.c b/epan/dissectors/packet-coap.c index 0508a0ee25..e61f6708be 100644 --- a/epan/dissectors/packet-coap.c +++ b/epan/dissectors/packet-coap.c @@ -296,7 +296,7 @@ dissect_coap_opt_hex_string(tvbuff_t *tvb, proto_item *item, proto_tree *subtree if (opt_length == 0) str = nullstr; else - str = tvb_bytes_to_ep_str_punct(tvb, offset, opt_length, ' '); + str = tvb_bytes_to_str_punct(wmem_packet_scope(), tvb, offset, opt_length, ' '); proto_tree_add_item(subtree, hf, tvb, offset, opt_length, ENC_NA); @@ -846,7 +846,7 @@ dissect_coap(tvbuff_t *tvb, packet_info *pinfo, proto_tree *parent_tree) coap_token_str = NULL; if (token_len > 0) { - coap_token_str = tvb_bytes_to_ep_str_punct(tvb, offset, token_len, ' '); + coap_token_str = tvb_bytes_to_str_punct(wmem_packet_scope(), tvb, offset, token_len, ' '); proto_tree_add_item(coap_tree, hf_coap_token, tvb, offset, token_len, ENC_NA); offset += token_len; diff --git a/epan/dissectors/packet-devicenet.c b/epan/dissectors/packet-devicenet.c index 1de05205b8..62c5438685 100644 --- a/epan/dissectors/packet-devicenet.c +++ b/epan/dissectors/packet-devicenet.c @@ -299,7 +299,7 @@ static gint body_type_8_over_8_dissection(guint8 data_length, proto_tree *device { length = offset-start_offset; proto_tree_add_bytes_format_value(devicenet_tree, hf_devicenet_data, tvb, offset, length, - NULL, "%s", tvb_bytes_to_ep_str_punct(tvb, offset, length, ' ')); + NULL, "%s", tvb_bytes_to_str_punct(wmem_packet_scope(), tvb, offset, length, ' ')); offset += length; } return offset; @@ -456,7 +456,7 @@ static int dissect_devicenet(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree col_set_str(pinfo->cinfo, COL_INFO, val_to_str_const(message_id, devicenet_grp_msg1_vals, "Other Group 1 Message")); proto_tree_add_bytes_format_value(devicenet_tree, hf_devicenet_data, tvb, offset, data_length, - NULL, "%s", tvb_bytes_to_ep_str_punct(tvb, offset, data_length, ' ')); + NULL, "%s", tvb_bytes_to_str_punct(wmem_packet_scope(), tvb, offset, data_length, ' ')); } /* * Message group 2 @@ -489,12 +489,12 @@ static int dissect_devicenet(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree case 0x4: case 0x5: proto_tree_add_bytes_format_value(content_tree, hf_devicenet_data, tvb, offset, data_length, - NULL, "%s", tvb_bytes_to_ep_str_punct(tvb, offset, data_length, ' ')); + NULL, "%s", tvb_bytes_to_str_punct(wmem_packet_scope(), tvb, offset, data_length, ' ')); break; case 0x6: proto_tree_add_bytes_format_value(content_tree, hf_devicenet_data, tvb, offset, data_length, - NULL, "%s", tvb_bytes_to_ep_str_punct(tvb, offset, data_length, ' ')); + NULL, "%s", tvb_bytes_to_str_punct(wmem_packet_scope(), tvb, offset, data_length, ' ')); break; case 0x7: @@ -647,7 +647,7 @@ static int dissect_devicenet(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree if(service_rr & CIP_SC_MASK) { proto_tree_add_bytes_format_value(devicenet_tree, hf_devicenet_data, tvb, offset, data_length - 2, - NULL, "%s", tvb_bytes_to_ep_str_punct(tvb, offset, data_length - 2, ' ')); + NULL, "%s", tvb_bytes_to_str_punct(wmem_packet_scope(), tvb, offset, data_length - 2, ' ')); } else { @@ -673,7 +673,7 @@ static int dissect_devicenet(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree break; default: proto_tree_add_bytes_format_value(content_tree, hf_devicenet_data, tvb, offset, data_length, - NULL, "%s", tvb_bytes_to_ep_str_punct(tvb, offset, data_length, ' ')); + NULL, "%s", tvb_bytes_to_str_punct(wmem_packet_scope(), tvb, offset, data_length, ' ')); break; } } diff --git a/epan/dissectors/packet-dhcpv6.c b/epan/dissectors/packet-dhcpv6.c index 22cdf3b050..cf5d2da812 100644 --- a/epan/dissectors/packet-dhcpv6.c +++ b/epan/dissectors/packet-dhcpv6.c @@ -1061,7 +1061,7 @@ dissect_cablelabs_specific_opts(proto_tree *v_tree, proto_item *v_item, packet_i opt_len = tlv_len; if (tlv_len == 3) { proto_item_append_text(ti, "%s", - tvb_bytes_to_ep_str_punct(tvb, sub_off, 3, ':')); + tvb_bytes_to_str_punct(wmem_packet_scope(), tvb, sub_off, 3, ':')); } else if (tlv_len == 6) { proto_item_append_text(ti, "\"%s\"", tvb_format_stringzpad(tvb, sub_off, tlv_len)); } else { @@ -1210,7 +1210,7 @@ dissect_cablelabs_specific_opts(proto_tree *v_tree, proto_item *v_item, packet_i } else { /*proto_item_append_text(ti, "CM MAC Address Option = %s", */ - proto_item_append_text(ti, "%s", tvb_bytes_to_ep_str_punct(tvb, sub_off, opt_len, ':')); + proto_item_append_text(ti, "%s", tvb_bytes_to_str_punct(wmem_packet_scope(), tvb, sub_off, opt_len, ':')); /* tvb_bytes_to_ep_str(tvb, sub_off, opt_len)); */ } break; diff --git a/epan/dissectors/packet-fcsb3.c b/epan/dissectors/packet-fcsb3.c index 62d099bea2..5c0abc61ad 100644 --- a/epan/dissectors/packet-fcsb3.c +++ b/epan/dissectors/packet-fcsb3.c @@ -800,7 +800,7 @@ static void dissect_fc_sbccs_dib_link_hdr (tvbuff_t *tvb, packet_info *pinfo, proto_tree_add_bytes_format(tree, hf_sbccs_logical_path, tvb, offset, 4, NULL, "Logical Paths %d-%d: %s", i*8, ((i+4)*8) - 1, - tvb_bytes_to_ep_str_punct (tvb, offset, 4, ':')); + tvb_bytes_to_str_punct(wmem_packet_scope(), tvb, offset, 4, ':')); i += 4; offset += 4; } diff --git a/epan/dissectors/packet-fip.c b/epan/dissectors/packet-fip.c index 0e35b84b78..fd25e20b96 100644 --- a/epan/dissectors/packet-fip.c +++ b/epan/dissectors/packet-fip.c @@ -453,7 +453,7 @@ dissect_fip(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree) proto_tree_add_item(subtree, hf_fip_desc_mac, desc_tvb, 2, 6, ENC_NA); proto_item_append_text(item, "%s", - tvb_bytes_to_ep_str_punct(desc_tvb, 2, 6, ':')); + tvb_bytes_to_str_punct(wmem_packet_scope(), desc_tvb, 2, 6, ':')); break; case FIP_DT_MAP_OUI: subtree = fip_desc_type_len(fip_tree, desc_tvb, dtype, ett_fip_dt_map, &item); @@ -503,7 +503,7 @@ dissect_fip(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree) proto_tree_add_item(subtree, hf_fip_desc_vn_wwpn, desc_tvb, 12, 8, ENC_NA); proto_item_append_text(item, "MAC %s FC_ID %6.6x", - tvb_bytes_to_ep_str_punct(desc_tvb, 2, 6, ':'), + tvb_bytes_to_str_punct(wmem_packet_scope(), desc_tvb, 2, 6, ':'), tvb_get_ntoh24(desc_tvb, 9)); break; case FIP_DT_FKA: diff --git a/epan/dissectors/packet-ismacryp.c b/epan/dissectors/packet-ismacryp.c index 927ce5f435..ad382b964f 100644 --- a/epan/dissectors/packet-ismacryp.c +++ b/epan/dissectors/packet-ismacryp.c @@ -567,7 +567,7 @@ static offset_struct* dissect_auheader( tvbuff_t *tvb, offset_struct *poffset, p ismacryp_item = proto_tree_add_item(ismacryp_header_tree, hf_ismacryp_iv, tvb, poffset->offset_bytes, iv_length, ENC_NA); proto_item_append_text(ismacryp_item, ": Length=%d bytes",iv_length); /* add IV info */ col_append_fstr( pinfo->cinfo, COL_INFO, - ", IV=0x%s", tvb_bytes_to_ep_str_punct(tvb, poffset->offset_bytes, iv_length,' ')); + ", IV=0x%s", tvb_bytes_to_str_punct(wmem_packet_scope(), tvb, poffset->offset_bytes, iv_length,' ')); poffset->offset_bytes+=iv_length; /* add IV length to offset_bytes */ } @@ -578,7 +578,7 @@ static offset_struct* dissect_auheader( tvbuff_t *tvb, offset_struct *poffset, p tvb, poffset->offset_bytes, delta_iv_length, ENC_NA); proto_item_append_text(ismacryp_item, ": Length=%d bytes",delta_iv_length); /* add delta IV info */ col_append_fstr( pinfo->cinfo, COL_INFO, - ", Delta IV=0x%s", tvb_bytes_to_ep_str_punct(tvb, poffset->offset_bytes, delta_iv_length,' ')); + ", Delta IV=0x%s", tvb_bytes_to_str_punct(wmem_packet_scope(), tvb, poffset->offset_bytes, delta_iv_length,' ')); poffset->offset_bytes+=iv_length; /* add IV length to offset_bytes */ } /* Key Indicator */ @@ -589,7 +589,7 @@ static offset_struct* dissect_auheader( tvbuff_t *tvb, offset_struct *poffset, p tvb, poffset->offset_bytes, key_indicator_length, ENC_NA); proto_item_append_text(ismacryp_item,": Length=%d bytes",key_indicator_length); /* add KI info */ col_append_fstr( pinfo->cinfo, COL_INFO, - ", KI=0x%s", tvb_bytes_to_ep_str_punct(tvb, poffset->offset_bytes, key_indicator_length,' ')); + ", KI=0x%s", tvb_bytes_to_str_punct(wmem_packet_scope(), tvb, poffset->offset_bytes, key_indicator_length,' ')); poffset->offset_bytes+=key_indicator_length; /* add KI length to offset_bytes */ } /* AU size */ diff --git a/epan/dissectors/packet-j1939.c b/epan/dissectors/packet-j1939.c index 31878c5581..514955fddb 100644 --- a/epan/dissectors/packet-j1939.c +++ b/epan/dissectors/packet-j1939.c @@ -241,7 +241,7 @@ static int dissect_j1939(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, vo col_add_fstr(pinfo->cinfo, COL_INFO, "PGN: %d", pgn); /* For now just include raw bytes */ - col_append_fstr(pinfo->cinfo, COL_INFO, " %s", tvb_bytes_to_ep_str_punct(tvb, 0, data_length, ' ')); + col_append_fstr(pinfo->cinfo, COL_INFO, " %s", tvb_bytes_to_str_punct(wmem_packet_scope(), tvb, 0, data_length, ' ')); msg_tree = proto_tree_add_subtree(j1939_tree, tvb, 0, -1, ett_j1939_message, NULL, "Message"); diff --git a/epan/dissectors/packet-netflow.c b/epan/dissectors/packet-netflow.c index 094de2bcf7..1dc726a9ef 100644 --- a/epan/dissectors/packet-netflow.c +++ b/epan/dissectors/packet-netflow.c @@ -5939,14 +5939,14 @@ dissect_v9_v10_pdu_data(tvbuff_t *tvb, packet_info *pinfo, proto_tree *pdutree, tvb, offset, length, NULL, "Type %u: Value (hex bytes): %s", masked_type, - tvb_bytes_to_ep_str_punct(tvb, offset, length, ' ')); + tvb_bytes_to_str_punct(wmem_packet_scope(), tvb, offset, length, ' ')); } else { /* v10 PEN */ ti = proto_tree_add_bytes_format_value(pdutree, hf_ipfix_enterprise_private_entry, tvb, offset, length, NULL, "(%s) Type %u: Value (hex bytes): %s", pen_str ? pen_str : "(null)", masked_type, - tvb_bytes_to_ep_str_punct(tvb, offset, length, ' ')); + tvb_bytes_to_str_punct(wmem_packet_scope(), tvb, offset, length, ' ')); } break; diff --git a/epan/dissectors/packet-opensafety.c b/epan/dissectors/packet-opensafety.c index 3cd200aa78..78d0fe3a17 100644 --- a/epan/dissectors/packet-opensafety.c +++ b/epan/dissectors/packet-opensafety.c @@ -1599,7 +1599,7 @@ dissect_opensafety_snmt_message(tvbuff_t *message_tvb, packet_info *pinfo, proto if ( global_scm_udid_autoset == TRUE ) { tempString = (char *)wmem_alloc0(wmem_packet_scope(), 128 * sizeof(char)); - g_snprintf ( tempString, 18, "%s", tvb_bytes_to_ep_str_punct(message_tvb, OSS_FRAME_POS_DATA + frameStart1 + 1, 6, ':' ) ); + g_snprintf ( tempString, 18, "%s", tvb_bytes_to_str_punct(wmem_packet_scope(), message_tvb, OSS_FRAME_POS_DATA + frameStart1 + 1, 6, ':' ) ); if ( memcmp ( global_scm_udid, tempString, 17 ) != 0 ) { local_scm_udid = (char *)wmem_alloc0(wmem_file_scope(), 18 * sizeof(char)); @@ -1641,7 +1641,7 @@ dissect_opensafety_snmt_message(tvbuff_t *message_tvb, packet_info *pinfo, proto if ( global_scm_udid_autoset == TRUE ) { tempString = (char *)wmem_alloc0(wmem_packet_scope(), 18 * sizeof(char)); - g_snprintf ( tempString, 18, "%s", tvb_bytes_to_ep_str_punct(message_tvb, OSS_FRAME_POS_DATA + frameStart1 + 1, 6, ':' ) ); + g_snprintf ( tempString, 18, "%s", tvb_bytes_to_str_punct(wmem_packet_scope(), message_tvb, OSS_FRAME_POS_DATA + frameStart1 + 1, 6, ':' ) ); if ( memcmp ( global_scm_udid, tempString, 17 ) != 0 ) { local_scm_udid = (char *)wmem_alloc0(wmem_file_scope(), 18 * sizeof(char)); diff --git a/epan/dissectors/packet-socketcan.c b/epan/dissectors/packet-socketcan.c index 83c2b49828..16da08b1c1 100644 --- a/epan/dissectors/packet-socketcan.c +++ b/epan/dissectors/packet-socketcan.c @@ -143,7 +143,7 @@ dissect_socketcan(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree) col_add_fstr(pinfo->cinfo, COL_INFO, "%s: 0x%08x", val_to_str(frame_type, frame_type_vals, "Unknown (0x%02x)"), can_id.id); col_append_fstr(pinfo->cinfo, COL_INFO, " %s", - tvb_bytes_to_ep_str_punct(tvb, CAN_DATA_OFFSET, frame_len, ' ')); + tvb_bytes_to_str_punct(wmem_packet_scope(), tvb, CAN_DATA_OFFSET, frame_len, ' ')); ti = proto_tree_add_item(tree, proto_can, tvb, 0, -1, ENC_NA); can_tree = proto_item_add_subtree(ti, ett_can); diff --git a/epan/dissectors/packet-zbee-zcl.c b/epan/dissectors/packet-zbee-zcl.c index e79fe739b7..aa24697011 100644 --- a/epan/dissectors/packet-zbee-zcl.c +++ b/epan/dissectors/packet-zbee-zcl.c @@ -1787,7 +1787,7 @@ void dissect_zcl_attr_data(tvbuff_t *tvb, proto_tree *tree, guint *offset, guint *offset += 1; proto_tree_add_item(tree, hf_zbee_zcl_attr_ostr, tvb, *offset, attr_uint, ENC_NA); - proto_item_append_text(tree, ", Octets: %s", tvb_bytes_to_ep_str_punct(tvb, *offset, attr_uint, ':')); + proto_item_append_text(tree, ", Octets: %s", tvb_bytes_to_str_punct(wmem_packet_scope(), tvb, *offset, attr_uint, ':')); *offset += attr_uint; break; @@ -1820,7 +1820,7 @@ void dissect_zcl_attr_data(tvbuff_t *tvb, proto_tree *tree, guint *offset, guint *offset += 2; proto_tree_add_item(tree, hf_zbee_zcl_attr_ostr, tvb, *offset, attr_uint, ENC_NA); - proto_item_append_text(tree, ", Octets: %s", tvb_bytes_to_ep_str_punct(tvb, *offset, attr_uint, ':')); + proto_item_append_text(tree, ", Octets: %s", tvb_bytes_to_str_punct(wmem_packet_scope(), tvb, *offset, attr_uint, ':')); *offset += attr_uint; break; diff --git a/epan/to_str.c b/epan/to_str.c index 4b77ddc2f8..4dfdddf099 100644 --- a/epan/to_str.c +++ b/epan/to_str.c @@ -155,6 +155,9 @@ bytes_to_hexstr_punct(char *out, const guint8 *ad, guint32 len, char punct) return out; } +/* Max string length for displaying byte string. */ +#define MAX_BYTE_STR_LEN 48 + /* Routine to convert a sequence of bytes to a hex string, one byte/two hex * digits at at a time, with a specified punctuation character between * the bytes. @@ -166,7 +169,12 @@ const gchar * bytestring_to_str(wmem_allocator_t *scope, const guint8 *ad, const guint32 len, const char punct) { gchar *buf; - size_t buflen; + size_t buflen = len; + gchar *buf_ptr; + int truncated = 0; + + if (!punct) + return bytes_to_str(scope, ad, len); if (!ad) REPORT_DISSECTOR_BUG("Null pointer passed to bytestring_to_str()"); @@ -174,25 +182,23 @@ bytestring_to_str(wmem_allocator_t *scope, const guint8 *ad, const guint32 len, if (len == 0) return wmem_strdup(scope, ""); - if (punct) - buflen=len*3; - else - buflen=len*2 + 1; + buf=(gchar *)wmem_alloc(scope, MAX_BYTE_STR_LEN+3+1); + if (buflen > MAX_BYTE_STR_LEN/3) { /* bd_len > 16 */ + truncated = 1; + buflen = MAX_BYTE_STR_LEN/3; + } - buf=(gchar *)wmem_alloc(scope, buflen); + buf_ptr = bytes_to_hexstr_punct(buf, ad, buflen, punct); /* max MAX_BYTE_STR_LEN-1 bytes */ - if (punct) - bytes_to_hexstr_punct(buf, ad, len, punct); - else - bytes_to_hexstr(buf, ad, len); + if (truncated) { + *buf_ptr++ = punct; /* 1 byte */ + buf_ptr = g_stpcpy(buf_ptr, "..."); /* 3 bytes */ + } - buf[buflen-1] = '\0'; + *buf_ptr = '\0'; return buf; } -/* Max string length for displaying byte string. */ -#define MAX_BYTE_STR_LEN 48 - gchar * bytes_to_ep_str(const guint8 *bd, int bd_len) { diff --git a/epan/tvbuff.c b/epan/tvbuff.c index 111b0ba0a1..2d9682034c 100644 --- a/epan/tvbuff.c +++ b/epan/tvbuff.c @@ -3405,9 +3405,9 @@ tvb_skip_guint8(tvbuff_t *tvb, int offset, const int maxlength, const guint8 ch) * separator. */ gchar * -tvb_bytes_to_ep_str_punct(tvbuff_t *tvb, const gint offset, const gint len, const gchar punct) +tvb_bytes_to_str_punct(wmem_allocator_t *scope, tvbuff_t *tvb, const gint offset, const gint len, const gchar punct) { - return bytes_to_ep_str_punct(ensure_contiguous(tvb, offset, len), len, punct); + return (gchar*)bytestring_to_str(scope, ensure_contiguous(tvb, offset, len), len, punct); } diff --git a/epan/tvbuff.h b/epan/tvbuff.h index a478e42058..5f08414e36 100644 --- a/epan/tvbuff.h +++ b/epan/tvbuff.h @@ -843,7 +843,7 @@ WS_DLL_PUBLIC gint tvb_memeql(tvbuff_t *tvb, const gint offset, * to the string with the formatted data, with "punct" as a byte * separator. */ -WS_DLL_PUBLIC gchar *tvb_bytes_to_ep_str_punct(tvbuff_t *tvb, const gint offset, +WS_DLL_PUBLIC gchar *tvb_bytes_to_str_punct(wmem_allocator_t *scope, tvbuff_t *tvb, const gint offset, const gint len, const gchar punct); /** |