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>
This commit is contained in:
Michael Mann 2015-01-07 08:29:35 -05:00
parent 493f03b420
commit 9cfe67fde6
15 changed files with 48 additions and 42 deletions

View File

@ -1296,7 +1296,7 @@ libwireshark.so.0 libwireshark0 #MINVER#
tvb_bcd_dig_to_wmem_packet_str@Base 1.12.0~rc1
tvb_bytes_exist@Base 1.9.1
tvb_bytes_to_ep_str@Base 1.12.0~rc1
tvb_bytes_to_ep_str_punct@Base 1.12.0~rc1
tvb_bytes_to_str_punct@Base 1.99.2
tvb_bytes_to_wmem_str@Base 1.99.2
tvb_captured_length@Base 1.12.0~rc1
tvb_captured_length_remaining@Base 1.12.0~rc1

View File

@ -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;

View File

@ -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;
}
}

View File

@ -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;

View File

@ -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;
}

View File

@ -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:

View File

@ -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 */

View File

@ -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");

View File

@ -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;

View File

@ -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));

View File

@ -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);

View File

@ -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;

View File

@ -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)
{

View File

@ -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);
}

View File

@ -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);
/**