More emem -> wmem conversion:

- tvb_get_g_stringz()/tvb_get_ephemeral_stringz()/tvb_get_seasonal_stringz() -> tvb_get_stringz()
- tvb_get_g_stringz_enc()/tvb_get_ephemeral_stringz_enc() -> tvb_get_stringz_enc()
- tvb_get_ephemeral_unicode_stringz() -> tvb_get_unicode_stringz()
- tvb_bcd_dig_to_ep_str() -> tvb_bcd_dig_to_wmem_packet_str()
- update docs accordingly

svn path=/trunk/; revision=52180
This commit is contained in:
Pascal Quantin 2013-09-22 20:04:35 +00:00
parent 1210a335ab
commit 102c452bcb
38 changed files with 187 additions and 274 deletions

View File

@ -648,7 +648,7 @@ dissect_ansi_map_min_type(tvbuff_t *tvb, packet_info *pinfo _U_, proto_tree *tre
subtree = proto_item_add_subtree(actx->created_item, ett_mintype);
digit_str = tvb_bcd_dig_to_ep_str(tvb, offset, tvb_length_remaining(tvb,offset), NULL, FALSE);
digit_str = tvb_bcd_dig_to_wmem_packet_str(tvb, offset, tvb_length_remaining(tvb,offset), NULL, FALSE);
proto_tree_add_string(subtree, hf_ansi_map_bcd_digits, tvb, offset, -1, digit_str);
proto_item_append_text(actx->created_item, " - %s", digit_str);
}
@ -693,7 +693,7 @@ dissect_ansi_map_digits_type(tvbuff_t *tvb, packet_info *pinfo _U_, proto_tree *
if(octet_len == 0)
return;
offset++;
digit_str = tvb_bcd_dig_to_ep_str(tvb, offset, tvb_length_remaining(tvb,offset), &Dgt_tbcd, FALSE);
digit_str = tvb_bcd_dig_to_wmem_packet_str(tvb, offset, tvb_length_remaining(tvb,offset), &Dgt_tbcd, FALSE);
proto_tree_add_string(subtree, hf_ansi_map_bcd_digits, tvb, offset, -1, digit_str);
proto_item_append_text(actx->created_item, " - %s", digit_str);
break;
@ -731,7 +731,7 @@ dissect_ansi_map_digits_type(tvbuff_t *tvb, packet_info *pinfo _U_, proto_tree *
switch ((octet&0xf)){
case 1:
/* BCD Coding */
digit_str = tvb_bcd_dig_to_ep_str(tvb, offset, tvb_length_remaining(tvb,offset), &Dgt_tbcd, FALSE);
digit_str = tvb_bcd_dig_to_wmem_packet_str(tvb, offset, tvb_length_remaining(tvb,offset), &Dgt_tbcd, FALSE);
proto_tree_add_string(subtree, hf_ansi_map_bcd_digits, tvb, offset, -1, digit_str);
proto_item_append_text(actx->created_item, " - %s", digit_str);
break;

View File

@ -476,7 +476,7 @@ NeighCellConfig TYPE=FT_UINT8 DISPLAY=BASE_DEC STRINGS=VALS(lte_rrc_neighCellCon
const gchar *str;
proto_tree *subtree;
subtree = proto_item_add_subtree(actx->created_item, ett_lte_rrc_absTimeInfo);
str = tvb_bcd_dig_to_ep_str(abs_time_info_tvb, 0, 6, NULL, FALSE);
str = tvb_bcd_dig_to_wmem_packet_str(abs_time_info_tvb, 0, 6, NULL, FALSE);
proto_tree_add_text(subtree, abs_time_info_tvb, 0, 6, "%c%c-%c%c-%c%c %c%c:%c%c:%c%c", str[0], str[1],
str[2], str[3], str[4], str[5], str[6], str[7], str[8], str[9], str[10], str[11]);
}

View File

@ -269,13 +269,10 @@ is intended for reading UTF-16 unicode strings out of a tvbuff and
returning them as a UTF-8 string for use in Wireshark. The offset and
returned length pointer are in bytes, not UTF-16 characters.
guint8 *tvb_get_stringz(tvbuff_t *tvb, const gint offset, gint *lengthp);
guint8 *tvb_get_stringz_enc(tvbuff_t *tvb, const gint offset, gint *lengthp, const guint encoding);
const guint8 *tvb_get_const stringz(tvbuff_t *tvb, const gint offset, gint *lengthp);
guint8 *tvb_get_ephemeral_stringz(tvbuff_t *tvb, const gint offset, gint *lengthp);
guint8 *tvb_get_ephemeral_stringz_enc(tvbuff_t *tvb, const gint offset, gint *lengthp, const guint encoding);
gchar *tvb_get_ephemeral_unicode_stringz(tvbuff_t *tvb, const gint offset, gint *lengthp, const guint encoding);
guint8 *tvb_get_seasonal_stringz(tvbuff_t *tvb, const gint offset, gint *lengthp);
guint8 *tvb_get_stringz(wmem_allocator_t *scope, tvbuff_t *tvb, const gint offset, gint *lengthp);
guint8 *tvb_get_stringz_enc(wmem_allocator_t *scope, tvbuff_t *tvb, const gint offset, gint *lengthp, const guint encoding);
const guint8 *tvb_get_const_stringz(tvbuff_t *tvb, const gint offset, gint *lengthp);
gchar *tvb_get_unicode_stringz(wmem_allocator_t *scope, tvbuff_t *tvb, const gint offset, gint *lengthp, const guint encoding);
gint tvb_get_nstringz(tvbuff_t *tvb, const gint offset, const guint bufsize, guint8* buffer);
gint tvb_get_nstringz0(tvbuff_t *tvb, const gint offset, const guint bufsize, guint8* buffer);
@ -285,30 +282,20 @@ tvbuff up to and including a terminating null character in the tvbuff.
"*lengthp" will be set to the length of the string, including the terminating
null.
tvb_get_stringz() returns a buffer allocated by g_malloc() so you must
g_free() it when you are finished with the string. Failure to g_free() this
buffer will lead to memory leaks.
tvb_get_stringz() returns a buffer allocated by g_malloc() if scope is set
to NULL (in that case memory must be explicitely freed), or with the
allocator lifetime if scope is not NULL.
tvb_get_const_stringz() returns a pointer to the (const) string in the tvbuff.
You do not need to free() this buffer, it will happen automatically once the
next packet is dissected. This function is slightly more efficient than the
others because it does not allocate memory and copy the string.
tvb_get_ephemeral_stringz() returns a buffer allocated from a special heap
with a lifetime until the next packet is dissected. You do not need to
free() this buffer, it will happen automatically once the next packet is
dissected.
tvb_get_ephemeral_unicode_stringz() is a unicode (UTF-16) version of
above. This is intended for reading UTF-16 unicode strings out of a tvbuff
tvb_get_unicode_stringz() is a unicode (UTF-16) version of above.
This is intended for reading UTF-16 unicode strings out of a tvbuff
and returning them as a UTF-8 string for use in Wireshark. The offset and
returned length pointer are in bytes, not UTF-16 characters.
tvb_get_seasonal_stringz() returns a buffer allocated from a special heap
with a lifetime of the current capture session. You do not need to
free() this buffer, it will happen automatically once the a new capture or
file is opened.
tvb_get_faked_unicode() has been superseded by tvb_get_string(), which
properly handles Unicode (UTF-16) strings by converting them to UTF-8.
@ -328,14 +315,14 @@ gchar *tvb_bytes_to_str_punct(tvbuff_t *tvb, gint offset, gint len, gchar punct)
This function is similar to tvb_bytes_to_str(...) except that 'punct' is inserted
between the hex representation of each byte.
gchar *tvb_bcd_dig_to_ep_str(tvbuff_t *tvb, const gint offset, const gint len, dgt_set_t *dgt, gboolean skip_first);
gchar *tvb_bcd_dig_to_wmem_packet_str(tvbuff_t *tvb, const gint offset, const gint len, dgt_set_t *dgt, gboolean skip_first);
Given a tvbuff, an offset into the tvbuff, and a length that starts
at that offset (which may be -1 for "all the way to the end of the
tvbuff"), fetch BCD encoded digits from a tvbuff starting from either
the low or high half byte, formatting the digits according to an input digit set,
if NUll a default digit set of 0-9 returning "?" for overdecadic digits will be used.
A pointer to the EP allocated string will be returned.
A pointer to the packet scope allocated string will be returned.
Note: a tvbuff content of 0xf is considered a 'filler' and will end the conversion.
Copying memory:

View File

@ -4576,7 +4576,7 @@ dissect_query_afp_spotlight(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree,
switch (request_val->spotlight_req_command) {
case SPOTLIGHT_CMD_GET_VOLPATH:
tvb_get_ephemeral_stringz(tvb, offset, &len);
tvb_get_stringz(wmem_packet_scope(), tvb, offset, &len);
proto_tree_add_item(tree, hf_afp_spotlight_volpath_client, tvb, offset, len, ENC_UTF_8|ENC_NA);
offset += len;
break;
@ -4792,7 +4792,7 @@ dissect_reply_afp_spotlight(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree,
proto_tree_add_item(tree, hf_afp_spotlight_reply_reserved, tvb, offset, 4, ENC_BIG_ENDIAN);
offset += 4;
tvb_get_ephemeral_stringz(tvb, offset, &len);
tvb_get_stringz(wmem_packet_scope(), tvb, offset, &len);
proto_tree_add_item(tree, hf_afp_spotlight_volpath_server, tvb, offset, len, ENC_UTF_8|ENC_NA);
offset += len;
break;

View File

@ -1436,7 +1436,7 @@ dissect_ansi_map_min_type(tvbuff_t *tvb, packet_info *pinfo _U_, proto_tree *tre
subtree = proto_item_add_subtree(actx->created_item, ett_mintype);
digit_str = tvb_bcd_dig_to_ep_str(tvb, offset, tvb_length_remaining(tvb,offset), NULL, FALSE);
digit_str = tvb_bcd_dig_to_wmem_packet_str(tvb, offset, tvb_length_remaining(tvb,offset), NULL, FALSE);
proto_tree_add_string(subtree, hf_ansi_map_bcd_digits, tvb, offset, -1, digit_str);
proto_item_append_text(actx->created_item, " - %s", digit_str);
}
@ -1481,7 +1481,7 @@ dissect_ansi_map_digits_type(tvbuff_t *tvb, packet_info *pinfo _U_, proto_tree *
if(octet_len == 0)
return;
offset++;
digit_str = tvb_bcd_dig_to_ep_str(tvb, offset, tvb_length_remaining(tvb,offset), &Dgt_tbcd, FALSE);
digit_str = tvb_bcd_dig_to_wmem_packet_str(tvb, offset, tvb_length_remaining(tvb,offset), &Dgt_tbcd, FALSE);
proto_tree_add_string(subtree, hf_ansi_map_bcd_digits, tvb, offset, -1, digit_str);
proto_item_append_text(actx->created_item, " - %s", digit_str);
break;
@ -1519,7 +1519,7 @@ dissect_ansi_map_digits_type(tvbuff_t *tvb, packet_info *pinfo _U_, proto_tree *
switch ((octet&0xf)){
case 1:
/* BCD Coding */
digit_str = tvb_bcd_dig_to_ep_str(tvb, offset, tvb_length_remaining(tvb,offset), &Dgt_tbcd, FALSE);
digit_str = tvb_bcd_dig_to_wmem_packet_str(tvb, offset, tvb_length_remaining(tvb,offset), &Dgt_tbcd, FALSE);
proto_tree_add_string(subtree, hf_ansi_map_bcd_digits, tvb, offset, -1, digit_str);
proto_item_append_text(actx->created_item, " - %s", digit_str);
break;

View File

@ -502,7 +502,7 @@ dissect_spoolss_string_parm_data(tvbuff_t *tvb, int offset, packet_info *pinfo,
offset = dissect_ndr_uint32(tvb, offset, pinfo, tree, drep,
hf_string_parm_size, &buffer_len);
s = tvb_get_ephemeral_unicode_stringz(tvb, offset, &len, ENC_LITTLE_ENDIAN);
s = tvb_get_unicode_stringz(wmem_packet_scope(), tvb, offset, &len, ENC_LITTLE_ENDIAN);
if (tree && buffer_len) {
tvb_ensure_bytes_exist(tvb, offset, buffer_len);

View File

@ -3054,7 +3054,7 @@ static void dissect_dmp_structured_id (tvbuff_t *tvb, proto_tree *body_tree,
break;
case STRUCT_ID_ZSTRING:
dmp.struct_id = tvb_get_ephemeral_stringz (tvb, offset, &length);
dmp.struct_id = tvb_get_stringz (wmem_packet_scope(), tvb, offset, &length);
proto_tree_add_item (body_tree, hf_message_bodyid_zstring, tvb, offset, length, ENC_ASCII|ENC_NA);
break;

View File

@ -633,15 +633,15 @@ dissect_dictionary(packet_info *pinfo, proto_tree *tree, tvbuff_t *tvb, int offs
*/
col_add_fstr(pinfo->cinfo, COL_INFO, "%s:%s > %s:%s",
tvb_get_ephemeral_stringz(tvb, offset + dict_data->source_scheme_offset, NULL),
tvb_get_ephemeral_stringz(tvb, offset + dict_data->source_ssp_offset, NULL),
tvb_get_ephemeral_stringz(tvb, offset + dict_data->dest_scheme_offset, NULL),
tvb_get_ephemeral_stringz(tvb, offset + dict_data->dest_ssp_offset, NULL));
tvb_get_stringz(wmem_packet_scope(), tvb, offset + dict_data->source_scheme_offset, NULL),
tvb_get_stringz(wmem_packet_scope(), tvb, offset + dict_data->source_ssp_offset, NULL),
tvb_get_stringz(wmem_packet_scope(), tvb, offset + dict_data->dest_scheme_offset, NULL),
tvb_get_stringz(wmem_packet_scope(), tvb, offset + dict_data->dest_ssp_offset, NULL));
/* remember custodian, for use in checking cteb validity */
*bundle_custodian = wmem_strdup_printf(wmem_packet_scope(), "%s:%s",
tvb_get_ephemeral_stringz(tvb, offset + dict_data->cust_scheme_offset, NULL),
tvb_get_ephemeral_stringz(tvb, offset + dict_data->cust_ssp_offset, NULL));
tvb_get_stringz(wmem_packet_scope(), tvb, offset + dict_data->cust_scheme_offset, NULL),
tvb_get_stringz(wmem_packet_scope(), tvb, offset + dict_data->cust_ssp_offset, NULL));
}
offset += dict_data->bundle_header_dict_length; /*Skip over dictionary*/

View File

@ -226,7 +226,7 @@ dissect_exec(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
if(hash_info->state == WAIT_FOR_STDERR_PORT
&& tvb_length_remaining(tvb, offset)){
field_stringz = tvb_get_ephemeral_stringz(tvb, offset, &length);
field_stringz = tvb_get_stringz(wmem_packet_scope(), tvb, offset, &length);
/* Check if this looks like the stderr_port field.
* It is optional, so it may only be 1 character long
@ -249,7 +249,7 @@ dissect_exec(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
if(hash_info->state == WAIT_FOR_USERNAME
&& tvb_length_remaining(tvb, offset)){
field_stringz = tvb_get_ephemeral_stringz(tvb, offset, &length);
field_stringz = tvb_get_stringz(wmem_packet_scope(), tvb, offset, &length);
/* Check if this looks like the username field */
if(length != 1 && length <= EXEC_USERNAME_LEN
@ -277,7 +277,7 @@ dissect_exec(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
if(hash_info->state == WAIT_FOR_PASSWORD
&& tvb_length_remaining(tvb, offset)){
field_stringz = tvb_get_ephemeral_stringz(tvb, offset, &length);
field_stringz = tvb_get_stringz(wmem_packet_scope(), tvb, offset, &length);
/* Check if this looks like the password field */
if(length != 1 && length <= EXEC_PASSWORD_LEN
@ -300,7 +300,7 @@ dissect_exec(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
if(hash_info->state == WAIT_FOR_COMMAND
&& tvb_length_remaining(tvb, offset)){
field_stringz = tvb_get_ephemeral_stringz(tvb, offset, &length);
field_stringz = tvb_get_stringz(wmem_packet_scope(), tvb, offset, &length);
/* Check if this looks like the command field */
if(length != 1 && length <= EXEC_COMMAND_LEN

View File

@ -3993,7 +3993,7 @@ dissect_reply_body (tvbuff_t *tvb, guint offset, packet_info *pinfo,
if (sequence_length != 0 && sequence_length < ITEM_LABEL_LENGTH)
{
header->exception_id = tvb_get_ephemeral_stringz(tvb,offset, &sequence_length);
header->exception_id = tvb_get_stringz(wmem_packet_scope(), tvb,offset, &sequence_length);
proto_tree_add_string(tree, hf_giop_exception_id, tvb, offset,
sequence_length, header->exception_id);

View File

@ -527,7 +527,7 @@ gluster_rpc_dissect_dict(proto_tree *tree, tvbuff_t *tvb, int hfindex, int offse
offset += 4;
/* read the key, '\0' terminated */
key = tvb_get_ephemeral_stringz(tvb, offset, &key_len);
key = tvb_get_stringz(wmem_packet_scope(), tvb, offset, &key_len);
start_offset2 = offset;
if (tree)
dict_item = proto_tree_add_text(subtree, tvb, offset, -1, "%s: ", key);

View File

@ -2237,7 +2237,7 @@ de_mid(tvbuff_t *tvb, proto_tree *tree, packet_info *pinfo, guint32 offset, guin
proto_tree_add_item(tree, hf_gsm_a_mobile_identity_type, tvb, curr_offset, 1, ENC_BIG_ENDIAN);
digit_str = tvb_bcd_dig_to_ep_str(tvb ,curr_offset , len - (curr_offset - offset), NULL, TRUE);
digit_str = tvb_bcd_dig_to_wmem_packet_str(tvb ,curr_offset , len - (curr_offset - offset), NULL, TRUE);
proto_tree_add_string_format(tree,
((oct & 0x07) == 3) ? hf_gsm_a_imeisv : hf_gsm_a_imsi,

View File

@ -357,7 +357,7 @@ dissect_ipa(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
}
if (global_ipa_in_info == TRUE)
col_append_fstr(pinfo->cinfo, COL_INFO, "%s ",
tvb_get_ephemeral_stringz(next_tvb, 0, NULL));
tvb_get_stringz(wmem_packet_scope(), next_tvb, 0, NULL));
break;
default:
if (msg_type < ABISIP_RSL_MAX) {

View File

@ -3215,7 +3215,7 @@ decode_gtp_imsi(tvbuff_t * tvb, int offset, packet_info * pinfo _U_, proto_tree
const gchar *imsi_str;
/* Octets 2 - 9 IMSI */
imsi_str = tvb_bcd_dig_to_ep_str( tvb, offset+1, 8, NULL, FALSE);
imsi_str = tvb_bcd_dig_to_wmem_packet_str( tvb, offset+1, 8, NULL, FALSE);
proto_tree_add_string(tree, hf_gtp_imsi, tvb, offset+1, 8, imsi_str);

View File

@ -872,7 +872,7 @@ dissect_gtpv2_imsi(tvbuff_t *tvb, packet_info *pinfo _U_, proto_tree *tree, prot
* a default digit set of 0-9 returning "?" for overdecadic digits a pointer to the EP
* allocated string will be returned.
*/
imsi_str = tvb_bcd_dig_to_ep_str( tvb, offset, length, NULL, FALSE);
imsi_str = tvb_bcd_dig_to_wmem_packet_str( tvb, offset, length, NULL, FALSE);
proto_tree_add_string(tree, hf_gtpv2_imsi, tvb, offset, length, imsi_str);
proto_item_append_text(item, "%s", imsi_str);
@ -1542,7 +1542,7 @@ dissect_gtpv2_mei(tvbuff_t *tvb, packet_info *pinfo _U_, proto_tree *tree, proto
* a default digit set of 0-9 returning "?" for overdecadic digits a pointer to the EP
* allocated string will be returned.
*/
mei_str = tvb_bcd_dig_to_ep_str( tvb, 0, length, NULL, FALSE);
mei_str = tvb_bcd_dig_to_wmem_packet_str( tvb, 0, length, NULL, FALSE);
proto_tree_add_string(tree, hf_gtpv2_mei, tvb, offset, length, mei_str);
proto_item_append_text(item, "%s", mei_str);
@ -1573,7 +1573,7 @@ dissect_gtpv2_msisdn(tvbuff_t *tvb, packet_info *pinfo _U_, proto_tree *tree, pr
* a default digit set of 0-9 returning "?" for overdecadic digits a pointer to the EP
* allocated string will be returned.
*/
digit_str = tvb_bcd_dig_to_ep_str( tvb, 0, length, NULL, FALSE);
digit_str = tvb_bcd_dig_to_wmem_packet_str( tvb, 0, length, NULL, FALSE);
proto_tree_add_string(tree, hf_gtpv2_address_digits, tvb, 0, length, digit_str);
proto_item_append_text(item, "%s", digit_str);
@ -2942,7 +2942,7 @@ dissect_gtpv2_mm_context_common_data(tvbuff_t *tvb, packet_info *pinfo, proto_tr
if (mei_len) {
const gchar *mei_str;
mei_str = tvb_bcd_dig_to_ep_str( tvb, offset, mei_len, NULL, FALSE);
mei_str = tvb_bcd_dig_to_wmem_packet_str( tvb, offset, mei_len, NULL, FALSE);
proto_tree_add_string(tree, hf_gtpv2_mei, tvb, offset, mei_len, mei_str);
offset += mei_len;
}

View File

@ -491,7 +491,7 @@ process_app0_segment(proto_tree *tree, tvbuff_t *tvb, guint32 len,
proto_tree_add_item(subtree, hf_len, tvb, 2, 2, ENC_BIG_ENDIAN);
str = tvb_get_ephemeral_stringz(tvb, 4, &str_size);
str = tvb_get_stringz(wmem_packet_scope(), tvb, 4, &str_size);
ti = proto_tree_add_item(subtree, hf_identifier, tvb, 4, str_size, ENC_ASCII|ENC_NA);
if (strcmp(str, "JFIF") == 0) {
/* Version */
@ -586,7 +586,7 @@ process_app1_segment(proto_tree *tree, tvbuff_t *tvb, guint32 len,
proto_tree_add_item(subtree, hf_len, tvb, offset, 2, ENC_BIG_ENDIAN);
offset += 2;
str = tvb_get_ephemeral_stringz(tvb, offset, &str_size);
str = tvb_get_stringz(wmem_packet_scope(), tvb, offset, &str_size);
ti = proto_tree_add_item(subtree, hf_identifier, tvb, offset, str_size, ENC_ASCII|ENC_NA);
offset += str_size;
if (strcmp(str, "Exif") == 0) {
@ -743,7 +743,7 @@ process_app2_segment(proto_tree *tree, tvbuff_t *tvb, guint32 len,
proto_tree_add_item(subtree, hf_len, tvb, 2, 2, ENC_BIG_ENDIAN);
str = tvb_get_ephemeral_stringz(tvb, 4, &str_size);
str = tvb_get_stringz(wmem_packet_scope(), tvb, 4, &str_size);
ti = proto_tree_add_item(subtree, hf_identifier, tvb, 4, str_size, ENC_ASCII|ENC_NA);
if (strcmp(str, "FPXR") == 0) {
proto_tree_add_text(tree, tvb, 0, -1, "Exif FlashPix APP2 application marker");

View File

@ -7536,7 +7536,7 @@ dissect_japan_isup_contractor_number(tvbuff_t *parameter_tvb, proto_tree *parame
proto_tree_add_item(parameter_tree, hf_isup_numbering_plan_indicator, parameter_tvb, offset, 1, ENC_BIG_ENDIAN);
offset++;
digit_str = tvb_bcd_dig_to_ep_str( parameter_tvb, offset, parameter_length-2, NULL, FALSE);
digit_str = tvb_bcd_dig_to_wmem_packet_str( parameter_tvb, offset, parameter_length-2, NULL, FALSE);
proto_tree_add_string(parameter_tree, hf_japan_isup_contractor_number, parameter_tvb, offset, parameter_length-offset, digit_str);
proto_item_set_text(parameter_item, "Contractor Number %s",digit_str);

View File

@ -24797,7 +24797,7 @@ dissect_lte_rrc_AbsoluteTimeInfo_r10(tvbuff_t *tvb _U_, int offset _U_, asn1_ctx
const gchar *str;
proto_tree *subtree;
subtree = proto_item_add_subtree(actx->created_item, ett_lte_rrc_absTimeInfo);
str = tvb_bcd_dig_to_ep_str(abs_time_info_tvb, 0, 6, NULL, FALSE);
str = tvb_bcd_dig_to_wmem_packet_str(abs_time_info_tvb, 0, 6, NULL, FALSE);
proto_tree_add_text(subtree, abs_time_info_tvb, 0, 6, "%c%c-%c%c-%c%c %c%c:%c%c:%c%c", str[0], str[1],
str[2], str[3], str[4], str[5], str[6], str[7], str[8], str[9], str[10], str[11]);
}

View File

@ -356,7 +356,7 @@ static guint16 evaluate_meta_item_dxt(proto_tree *meta_tree, tvbuff_t *tvb, pack
break;
case META_ID_IMSI:
imsi = tvb_get_letoh64(tvb, offs);
imsi_str = tvb_bcd_dig_to_ep_str(tvb, offs, 8, NULL, FALSE);
imsi_str = tvb_bcd_dig_to_wmem_packet_str(tvb, offs, 8, NULL, FALSE);
imsi_item = proto_tree_add_string(meta_tree, hf_meta_item_imsi_digits, tvb,
offs, 8, imsi_str);
imsi_tree = proto_item_add_subtree(imsi_item, ett_meta_imsi);
@ -365,7 +365,7 @@ static guint16 evaluate_meta_item_dxt(proto_tree *meta_tree, tvbuff_t *tvb, pack
break;
case META_ID_IMEI:
imei = tvb_get_letoh64(tvb, offs);
imei_str = tvb_bcd_dig_to_ep_str(tvb, offs, 8, NULL, FALSE);
imei_str = tvb_bcd_dig_to_wmem_packet_str(tvb, offs, 8, NULL, FALSE);
imei_item = proto_tree_add_string(meta_tree, hf_meta_item_imei_digits, tvb,
offs, 8, imei_str);
imei_tree = proto_item_add_subtree(imei_item, ett_meta_imei);

View File

@ -1793,14 +1793,14 @@ dissect_mip6_opt_vsm_3gpp(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, v
break;
/* 11, Mobile Equipment Identity (MEI) */
case 11:
mei_str = tvb_bcd_dig_to_ep_str( tvb, offset, len, NULL, FALSE);
mei_str = tvb_bcd_dig_to_wmem_packet_str( tvb, offset, len, NULL, FALSE);
proto_tree_add_string(tree, hf_mip6_opt_3gpp_mei, tvb, offset, len, mei_str);
proto_item_append_text(hdr_item, " %s", mei_str);
break;
/* 12, MSISDN */
case 12:
dissect_e164_cc(tvb, tree, offset, TRUE);
digit_str = tvb_bcd_dig_to_ep_str( tvb, offset, len, NULL, FALSE);
digit_str = tvb_bcd_dig_to_wmem_packet_str( tvb, offset, len, NULL, FALSE);
proto_tree_add_string(tree, hf_mip6_opt_3gpp_msisdn, tvb, offset, len, digit_str);
proto_item_append_text(hdr_item, " %s", digit_str);
break;
@ -1819,7 +1819,7 @@ dissect_mip6_opt_vsm_3gpp(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, v
break;
/* 16, Unauthenticated IMSI */
case 16:
imsi_str = tvb_bcd_dig_to_ep_str( tvb, offset, len, NULL, FALSE);
imsi_str = tvb_bcd_dig_to_wmem_packet_str( tvb, offset, len, NULL, FALSE);
proto_tree_add_string(tree, hf_mip6_opt_3gpp_imsi, tvb, offset, len, imsi_str);
proto_item_append_text(hdr_item," %s", imsi_str);
break;

View File

@ -296,7 +296,7 @@ dissect_bson_document(tvbuff_t *tvb, packet_info *pinfo, guint offset, proto_tre
gint doc_len = -1; /* Document length */
e_type = tvb_get_guint8(tvb, offset);
tvb_get_ephemeral_stringz(tvb, offset+1, &str_len);
tvb_get_stringz(wmem_packet_scope(), tvb, offset+1, &str_len);
element = proto_tree_add_item(elements_tree, hf_mongo_element_name, tvb, offset+1, str_len-1, ENC_UTF_8|ENC_NA);
element_sub_tree = proto_item_add_subtree(element, ett_mongo_element);
@ -350,11 +350,11 @@ dissect_bson_document(tvbuff_t *tvb, packet_info *pinfo, guint offset, proto_tre
break;
case BSON_ELEMENT_TYPE_REGEX:
/* regex pattern */
tvb_get_ephemeral_stringz(tvb, offset, &str_len);
tvb_get_stringz(wmem_packet_scope(), tvb, offset, &str_len);
proto_tree_add_item(element_sub_tree, hf_mongo_element_value_regex_pattern, tvb, offset, str_len, ENC_UTF_8|ENC_NA);
offset += str_len;
/* regex options */
tvb_get_ephemeral_stringz(tvb, offset, &str_len);
tvb_get_stringz(wmem_packet_scope(), tvb, offset, &str_len);
proto_tree_add_item(element_sub_tree, hf_mongo_element_value_regex_options, tvb, offset, str_len, ENC_UTF_8|ENC_NA);
offset += str_len;
break;

View File

@ -387,7 +387,7 @@ static void dissect_pgsql_fe_msg(guchar type, guint length, tvbuff_t *tvb,
if (i != 0) {
n += 1;
s = tvb_get_ephemeral_stringz(tvb, n, &siz);
s = tvb_get_stringz(wmem_packet_scope(), tvb, n, &siz);
hidden_item = proto_tree_add_string(tree, i, tvb, n, siz, s);
PROTO_ITEM_SET_HIDDEN(hidden_item);
proto_tree_add_text(
@ -511,11 +511,11 @@ static void dissect_pgsql_be_msg(guchar type, guint length, tvbuff_t *tvb,
/* Parameter status */
case 'S':
s = tvb_get_ephemeral_stringz(tvb, n, &siz);
s = tvb_get_stringz(wmem_packet_scope(), tvb, n, &siz);
hidden_item = proto_tree_add_string(tree, hf_parameter_name, tvb, n, siz, s);
PROTO_ITEM_SET_HIDDEN(hidden_item);
n += siz;
t = tvb_get_ephemeral_stringz(tvb, n, &i);
t = tvb_get_stringz(wmem_packet_scope(), tvb, n, &i);
hidden_item = proto_tree_add_string(tree, hf_parameter_value, tvb, n, i, t);
PROTO_ITEM_SET_HIDDEN(hidden_item);
proto_tree_add_text(tree, tvb, n-siz, siz+i, "%s: %s", s, t);
@ -595,7 +595,7 @@ static void dissect_pgsql_be_msg(guchar type, guint length, tvbuff_t *tvb,
c = tvb_get_guint8(tvb, n);
if (c == '\0')
break;
s = tvb_get_ephemeral_stringz(tvb, n+1, &siz);
s = tvb_get_stringz(wmem_packet_scope(), tvb, n+1, &siz);
i = hf_text;
switch (c) {
case 'S': i = hf_severity; break;

View File

@ -236,7 +236,7 @@ dissect_rsh(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
if(hash_info->state == WAIT_FOR_STDERR_PORT
&& tvb_length_remaining(tvb, offset)){
field_stringz = tvb_get_ephemeral_stringz(tvb, offset, &length);
field_stringz = tvb_get_stringz(wmem_packet_scope(), tvb, offset, &length);
/* Check if this looks like the stderr_port field.
* It is optional, so it may only be 1 character long
@ -259,7 +259,7 @@ dissect_rsh(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
if(hash_info->state == WAIT_FOR_CLIENT_USERNAME
&& tvb_length_remaining(tvb, offset)){
field_stringz = tvb_get_ephemeral_stringz(tvb, offset, &length);
field_stringz = tvb_get_stringz(wmem_packet_scope(), tvb, offset, &length);
/* Check if this looks like the username field */
if(length != 1 && length <= RSH_CLIENT_USERNAME_LEN
@ -287,7 +287,7 @@ dissect_rsh(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
if(hash_info->state == WAIT_FOR_SERVER_USERNAME
&& tvb_length_remaining(tvb, offset)){
field_stringz = tvb_get_ephemeral_stringz(tvb, offset, &length);
field_stringz = tvb_get_stringz(wmem_packet_scope(), tvb, offset, &length);
/* Check if this looks like the password field */
if(length != 1 && length <= RSH_SERVER_USERNAME_LEN
@ -317,7 +317,7 @@ dissect_rsh(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
if(hash_info->state == WAIT_FOR_COMMAND
&& tvb_length_remaining(tvb, offset)){
field_stringz = tvb_get_ephemeral_stringz(tvb, offset, &length);
field_stringz = tvb_get_stringz(wmem_packet_scope(), tvb, offset, &length);
/* Check if this looks like the command field */
if(length != 1 && length <= RSH_COMMAND_LEN

View File

@ -192,7 +192,7 @@ de_sgsap_imeisv(tvbuff_t *tvb, proto_tree *tree, packet_info *pinfo _U_, guint32
curr_offset = offset;
imeisv_str = tvb_bcd_dig_to_ep_str( tvb, curr_offset, len, NULL, FALSE);
imeisv_str = tvb_bcd_dig_to_wmem_packet_str( tvb, curr_offset, len, NULL, FALSE);
proto_tree_add_string(tree, hf_sgsap_imeisv, tvb, curr_offset, len, imeisv_str);
if (add_string) {
/* (len<<2)+4 = the maximum number of bytes to produce (including the terminating nul character). */

View File

@ -701,7 +701,7 @@ dissect_mailslot_browse(tvbuff_t *tvb, packet_info *pinfo, proto_tree *parent_tr
offset += 1;
/* name of computer to which to send reply */
computer_name = tvb_get_ephemeral_stringz(tvb, offset, &namelen);
computer_name = tvb_get_stringz(wmem_packet_scope(), tvb, offset, &namelen);
proto_tree_add_string(tree, hf_response_computer_name,
tvb, offset, namelen, computer_name);
col_append_fstr(pinfo->cinfo, COL_INFO, " %s", computer_name);

View File

@ -65,7 +65,7 @@ int display_ms_string(tvbuff_t *tvb, proto_tree *tree, int offset, int hf_index,
/* display a string from the tree and return the new offset */
str = tvb_get_ephemeral_stringz(tvb, offset, &len);
str = tvb_get_stringz(wmem_packet_scope(), tvb, offset, &len);
proto_tree_add_string(tree, hf_index, tvb, offset, len, str);
/* Return a copy of the string if requested */

View File

@ -11171,9 +11171,9 @@ dissect_transaction2_request_parameters(tvbuff_t *tvb, packet_info *pinfo,
/* file name */
if (si->unicode)
fn = tvb_get_ephemeral_unicode_stringz(tvb, offset, &fn_len, ENC_LITTLE_ENDIAN);
fn = tvb_get_unicode_stringz(wmem_packet_scope(), tvb, offset, &fn_len, ENC_LITTLE_ENDIAN);
else
fn = tvb_get_ephemeral_stringz(tvb, offset, &fn_len);
fn = tvb_get_stringz(wmem_packet_scope(), tvb, offset, &fn_len);
CHECK_STRING_TRANS(fn);
proto_tree_add_string(tree, hf_smb_file_name, tvb, offset, fn_len,

View File

@ -1248,7 +1248,7 @@ smpp_handle_string_return(proto_tree *tree, tvbuff_t *tvb, int field, int *offse
len = tvb_strsize(tvb, *offset);
if (len > 1) {
str = (char *)tvb_get_ephemeral_stringz(tvb, *offset, &len);
str = (char *)tvb_get_stringz(wmem_packet_scope(), tvb, *offset, &len);
proto_tree_add_string(tree, field, tvb, *offset, len, str);
} else {
str = "";
@ -1310,7 +1310,7 @@ smpp_handle_time(proto_tree *tree, tvbuff_t *tvb,
gint len;
nstime_t tmptime;
strval = (char *) tvb_get_ephemeral_stringz(tvb, *offset, &len);
strval = (char *) tvb_get_stringz(wmem_packet_scope(), tvb, *offset, &len);
if (*strval)
{
if (len >= 16)

View File

@ -1968,7 +1968,7 @@ dissect_spice_common_server_messages(tvbuff_t *tvb, proto_tree *tree, const guin
message_len = tvb_get_letohl(tvb, offset);
proto_tree_add_text(server_message_tree, tvb, offset, 4, "message length: %d", message_len);
offset += 4;
/*TODO use proto_tree_add_string and get the stringz using tvb_get_ephemeral_stringz() */
/*TODO use proto_tree_add_string and get the stringz using tvb_get_stringz() */
proto_tree_add_text(server_message_tree, tvb, offset, message_len + 1, "Message content");
offset += (message_len + 1);
break;

View File

@ -632,13 +632,13 @@ static void ts2_parse_channellist(tvbuff_t *tvb, proto_tree *ts2_tree)
offset+=2;
proto_tree_add_item(ts2_tree, hf_ts2_max_users, tvb, offset, 2, ENC_LITTLE_ENDIAN);
offset+=2;
tvb_get_ephemeral_stringz(tvb, offset, &string_len);
tvb_get_stringz(wmem_packet_scope(), tvb, offset, &string_len);
proto_tree_add_item(ts2_tree, hf_ts2_channel_name, tvb, offset,string_len , ENC_ASCII|ENC_NA);
offset+=string_len;
tvb_get_ephemeral_stringz(tvb, offset, &string_len);
tvb_get_stringz(wmem_packet_scope(), tvb, offset, &string_len);
proto_tree_add_item(ts2_tree, hf_ts2_channel_topic, tvb, offset,string_len ,ENC_ASCII|ENC_NA);
offset+=string_len;
tvb_get_ephemeral_stringz(tvb, offset, &string_len);
tvb_get_stringz(wmem_packet_scope(), tvb, offset, &string_len);
proto_tree_add_item(ts2_tree, hf_ts2_channel_description, tvb, offset,string_len , ENC_ASCII|ENC_NA);
offset+=string_len;
}

View File

@ -179,7 +179,7 @@ static void dissect_turbocell(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tre
name_item = proto_tree_add_item(turbocell_tree, hf_turbocell_name, tvb, 0x14, 30, ENC_ASCII|ENC_NA);
network_tree = proto_item_add_subtree(name_item, ett_network);
str_name=tvb_get_ephemeral_stringz(tvb, 0x14, &str_len);
str_name=tvb_get_stringz(wmem_packet_scope(), tvb, 0x14, &str_len);
col_append_fstr(pinfo->cinfo, COL_INFO, ", Network=\"%s\"",format_text(str_name, str_len-1));
while(tvb_get_guint8(tvb, 0x34 + 8*i)==0x00 && (tvb_length_remaining(tvb,0x34 + 8*i) > 6) && (i<32)) {

View File

@ -382,7 +382,7 @@ dissect_wow_pdu(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
offset += 2;
for(ii = 0; ii < num_realms; ii++) {
realm_name = tvb_get_ephemeral_stringz(tvb,
realm_name = tvb_get_stringz(wmem_packet_scope(), tvb,
offset + 3,
&len);
@ -404,7 +404,7 @@ dissect_wow_pdu(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
proto_tree_add_string(wow_realms_tree, hf_wow_realm_name, tvb, offset, len, realm_name);
offset += len;
string = tvb_get_ephemeral_stringz(tvb, offset,
string = tvb_get_stringz(wmem_packet_scope(), tvb, offset,
&len);
proto_tree_add_string(wow_realms_tree, hf_wow_realm_socket, tvb, offset, len, string);
offset += len;

View File

@ -1282,7 +1282,7 @@ static void add_headers (proto_tree *tree, tvbuff_t *tvb, int hf, packet_info *p
* get_text_string() macro now returns wmem_alloc'd memory. */
#define get_text_string(str,tvb,start,len,ok) \
if (is_text_string(tvb_get_guint8(tvb,start))) { \
str = (gchar *)tvb_get_ephemeral_stringz(tvb,start,(gint *)&len); \
str = (gchar *)tvb_get_stringz(wmem_packet_scope(), tvb,start,(gint *)&len); \
ok = TRUE; \
} else { len = 0; str = NULL; ok = FALSE; }
#define get_token_text(str,tvb,start,len,ok) \
@ -1782,12 +1782,12 @@ add_headers (proto_tree *tree, tvbuff_t *tvb, int hf, packet_info *pinfo)
offset += 2;
} else if (hdr_id >= 0x20) { /* Textual header */
/* Header name MUST be NUL-ended string ==> tvb_get_stringz() */
hdr_str = (gchar *)tvb_get_ephemeral_stringz(tvb, hdr_start, (gint *)&hdr_len);
hdr_str = (gchar *)tvb_get_stringz(wmem_packet_scope(), tvb, hdr_start, (gint *)&hdr_len);
val_start = hdr_start + hdr_len;
val_id = tvb_get_guint8(tvb, val_start);
/* Call header value dissector for given header */
if (val_id >= 0x20 && val_id <=0x7E) { /* OK! */
val_str = (gchar *)tvb_get_ephemeral_stringz(tvb, val_start, (gint *)&val_len);
val_str = (gchar *)tvb_get_stringz(wmem_packet_scope(), tvb, val_start, (gint *)&val_len);
offset = val_start + val_len;
tvb_ensure_bytes_exist(tvb, hdr_start, offset-hdr_start);
proto_tree_add_text(wsp_headers,tvb,hdr_start,offset-hdr_start,
@ -1911,7 +1911,7 @@ add_headers (proto_tree *tree, tvbuff_t *tvb, int hf, packet_info *pinfo)
#define wkh_2_TextualValue /* Parse Textual Value */ \
/* END */ \
} else if ((val_id == 0) || (val_id >= 0x20)) { /* Textual value */ \
val_str = (gchar *)tvb_get_ephemeral_stringz (tvb, val_start, (gint *)&val_len); \
val_str = (gchar *)tvb_get_stringz (wmem_packet_scope(), tvb, val_start, (gint *)&val_len); \
offset = val_start + val_len; \
/* Textual value processing starts HERE \
* \
@ -1920,7 +1920,7 @@ add_headers (proto_tree *tree, tvbuff_t *tvb, int hf, packet_info *pinfo)
#define wkh_2_TextualValueInv /* Parse Textual Value */ \
/* END */ \
} else if ((val_id == 0) || (val_id >= 0x20)) { /* Textual value */ \
/*val_str = (gchar *)*/tvb_get_ephemeral_stringz (tvb, val_start, (gint *)&val_len); \
/*val_str = (gchar *)*/tvb_get_stringz (wmem_packet_scope(), tvb, val_start, (gint *)&val_len); \
offset = val_start + val_len; \
/* Textual value processing starts HERE \
* \

View File

@ -1471,10 +1471,7 @@ proto_tree_new_item(field_info *new_fi, proto_tree *tree,
*/
if (length == -1) {
/* This can throw an exception */
string = tvb_get_ephemeral_stringz_enc(tvb, start, &length, encoding);
string = tvb_get_stringz_enc(wmem_packet_scope(), tvb, start, &length, encoding);
} else if (length == 0) {
string = "[Empty]";
} else {

View File

@ -47,7 +47,6 @@
#include "tvbuff.h"
#include "tvbuff-int.h"
#include "strutil.h"
#include "emem.h"
#include "charsets.h"
#include "proto.h" /* XXX - only used for DISSECTOR_ASSERT, probably a new header file? */
@ -2049,34 +2048,102 @@ tvb_get_string_enc(wmem_allocator_t *scope, tvbuff_t *tvb, const gint offset,
}
/*
* Given a tvbuff, an offset, and an encoding, with the offset assumed
* to refer to a null-terminated string, find the length of that string
* (and throw an exception if the tvbuff ends before we find the null),
* allocate a buffer big enough to hold the string, copy the string into
* it, and return a pointer to the string; if the encoding is EBCDIC, map
* the string from EBCDIC to ASCII. Also return the length of the
* Given a tvbuff and an offset, with the offset assumed to refer to
* a null-terminated string, find the length of that string (and throw
* an exception if the tvbuff ends before we find the null), allocate
* a buffer big enough to hold the string, copy the string into it,
* and return a pointer to the string. Also return the length of the
* string (including the terminating null) through a pointer.
*
* If scope is NULL, memory is allocated with g_malloc() and user must
* explicitely free it with g_free().
* If scope is not NULL, memory is allocated with the corresponding pool
* lifetime.
*/
guint8 *
tvb_get_g_stringz_enc(tvbuff_t *tvb, const gint offset, gint *lengthp, const guint encoding)
tvb_get_stringz(wmem_allocator_t *scope, tvbuff_t *tvb, const gint offset, gint *lengthp)
{
guint size;
guint8 *strptr;
size = tvb_strsize(tvb, offset);
strptr = (guint8 *)g_malloc(size);
strptr = (guint8 *)wmem_alloc(scope, size);
tvb_memcpy(tvb, strptr, offset, size);
if ((encoding & ENC_CHARENCODING_MASK) == ENC_EBCDIC)
EBCDIC_to_ASCII(strptr, size);
if (lengthp)
*lengthp = size;
return strptr;
}
guint8 *
tvb_get_g_stringz(tvbuff_t *tvb, const gint offset, gint *lengthp)
tvb_get_stringz_enc(wmem_allocator_t *scope, tvbuff_t *tvb, const gint offset, gint *lengthp, const guint encoding)
{
return tvb_get_g_stringz_enc(tvb, offset, lengthp, ENC_UTF_8|ENC_NA);
guint size;
guint8 *strptr;
switch (encoding & ENC_CHARENCODING_MASK) {
case ENC_ASCII:
default:
/*
* For now, we treat bogus values as meaning
* "ASCII" rather than reporting an error,
* for the benefit of old dissectors written
* when the last argument to proto_tree_add_item()
* was a gboolean for the byte order, not an
* encoding value, and passed non-zero values
* other than TRUE to mean "little-endian".
*
* XXX - should map all octets with the 8th bit
* not set to a "substitute" UTF-8 character.
*/
strptr = tvb_get_stringz(scope, tvb, offset, lengthp);
break;
case ENC_UTF_8:
/*
* XXX - should map all invalid UTF-8 sequences
* to a "substitute" UTF-8 character.
*/
strptr = tvb_get_stringz(scope, tvb, offset, lengthp);
break;
case ENC_UTF_16:
/*
* XXX - needs to handle surrogate pairs and to map
* invalid characters and sequences to a "substitute"
* UTF-8 character.
*/
strptr = tvb_get_unicode_stringz(scope, tvb, offset, lengthp,
encoding & ENC_LITTLE_ENDIAN);
break;
case ENC_UCS_2:
/*
* XXX - needs to map values that are not valid UCS-2
* characters (such as, I think, values used as the
* components of a UTF-16 surrogate pair) to a
* "substitute" UTF-8 character.
*/
strptr = tvb_get_unicode_stringz(scope, tvb, offset, lengthp,
encoding & ENC_LITTLE_ENDIAN);
break;
case ENC_EBCDIC:
/*
* XXX - do the copy and conversion in one pass.
*
* XXX - multiple "dialects" of EBCDIC?
*/
size = tvb_strsize(tvb, offset);
strptr = (guint8 *)wmem_alloc(scope, size);
tvb_memcpy(tvb, strptr, offset, size);
EBCDIC_to_ASCII(strptr, size);
if (lengthp)
*lengthp = size;
break;
}
return strptr;
}
/*
@ -2106,123 +2173,23 @@ tvb_get_const_stringz(tvbuff_t *tvb, const gint offset, gint *lengthp)
}
/*
* Given a tvbuff and an offset, with the offset assumed to refer to
* a null-terminated string, find the length of that string (and throw
* an exception if the tvbuff ends before we find the null), allocate
* a buffer big enough to hold the string, copy the string into it,
* and return a pointer to the string. Also return the length of the
* string (including the terminating null) through a pointer.
*
* This function allocates memory from a buffer with packet lifetime.
* You do not have to free this buffer, it will be automatically freed
* when wireshark starts decoding the next packet.
* Do not use this function if you want the allocated memory to be persistent
* after the current packet has been dissected.
*/
guint8 *
tvb_get_ephemeral_stringz_enc(tvbuff_t *tvb, const gint offset, gint *lengthp, const guint encoding)
{
guint size;
guint8 *strptr;
switch (encoding & ENC_CHARENCODING_MASK) {
case ENC_ASCII:
default:
/*
* For now, we treat bogus values as meaning
* "ASCII" rather than reporting an error,
* for the benefit of old dissectors written
* when the last argument to proto_tree_add_item()
* was a gboolean for the byte order, not an
* encoding value, and passed non-zero values
* other than TRUE to mean "little-endian".
*
* XXX - should map all octets with the 8th bit
* not set to a "substitute" UTF-8 character.
*/
strptr = tvb_get_ephemeral_stringz(tvb, offset, lengthp);
break;
case ENC_UTF_8:
/*
* XXX - should map all invalid UTF-8 sequences
* to a "substitute" UTF-8 character.
*/
strptr = tvb_get_ephemeral_stringz(tvb, offset, lengthp);
break;
case ENC_UTF_16:
/*
* XXX - needs to handle surrogate pairs and to map
* invalid characters and sequences to a "substitute"
* UTF-8 character.
*/
strptr = tvb_get_ephemeral_unicode_stringz(tvb, offset, lengthp,
encoding & ENC_LITTLE_ENDIAN);
break;
case ENC_UCS_2:
/*
* XXX - needs to map values that are not valid UCS-2
* characters (such as, I think, values used as the
* components of a UTF-16 surrogate pair) to a
* "substitute" UTF-8 character.
*/
strptr = tvb_get_ephemeral_unicode_stringz(tvb, offset, lengthp,
encoding & ENC_LITTLE_ENDIAN);
break;
case ENC_EBCDIC:
/*
* XXX - do the copy and conversion in one pass.
*
* XXX - multiple "dialects" of EBCDIC?
*/
size = tvb_strsize(tvb, offset);
strptr = (guint8 *)ep_alloc(size);
tvb_memcpy(tvb, strptr, offset, size);
EBCDIC_to_ASCII(strptr, size);
if (lengthp)
*lengthp = size;
break;
}
return strptr;
}
guint8 *
tvb_get_ephemeral_stringz(tvbuff_t *tvb, const gint offset, gint *lengthp)
{
guint size;
guint8 *strptr;
size = tvb_strsize(tvb, offset);
strptr = (guint8 *)ep_alloc(size);
tvb_memcpy(tvb, strptr, offset, size);
if (lengthp)
*lengthp = size;
return strptr;
}
/*
* Unicode (UTF-16) version of tvb_get_ephemeral_stringz()
* Unicode (UTF-16) version of tvb_get_stringz()
*
* Encoding paramter should be ENC_BIG_ENDIAN or ENC_LITTLE_ENDIAN
*
* Returns an ep_ allocated UTF-8 string and updates lengthp pointer with length of string (in bytes)
* Returns an allocated UTF-8 string and updates lengthp pointer with length of string (in bytes)
*/
gchar *
tvb_get_ephemeral_unicode_stringz(tvbuff_t *tvb, const gint offset, gint *lengthp, const guint encoding)
tvb_get_unicode_stringz(wmem_allocator_t *scope, tvbuff_t *tvb, const gint offset, gint *lengthp, const guint encoding)
{
gunichar2 uchar;
gint size; /* Number of UTF-16 characters */
gint i; /* Byte counter for tvbuff */
emem_strbuf_t *strbuf;
wmem_strbuf_t *strbuf;
size = tvb_unicode_strsize(tvb, offset);
strbuf = ep_strbuf_new(NULL);
strbuf = wmem_strbuf_new(scope, NULL);
for(i = 0; i < size; i += 2) {
if (encoding == ENC_BIG_ENDIAN)
@ -2230,39 +2197,13 @@ tvb_get_ephemeral_unicode_stringz(tvbuff_t *tvb, const gint offset, gint *length
else
uchar = tvb_get_letohs(tvb, offset + i);
ep_strbuf_append_unichar(strbuf, uchar);
wmem_strbuf_append_unichar(strbuf, uchar);
}
if (lengthp)
*lengthp = i; /* Number of *bytes* processed */
return strbuf->str;
}
/*
* Given a tvbuff and an offset, with the offset assumed to refer to
* a null-terminated string, find the length of that string (and throw
* an exception if the tvbuff ends before we find the null), allocate
* a buffer big enough to hold the string, copy the string into it,
* and return a pointer to the string. Also return the length of the
* string (including the terminating null) through a pointer.
*
* This function allocates memory from a buffer with capture session lifetime.
* You do not have to free this buffer, it will be automatically freed
* when wireshark starts or opens a new capture.
*/
guint8 *
tvb_get_seasonal_stringz(tvbuff_t *tvb, const gint offset, gint *lengthp)
{
guint size;
guint8 *strptr;
size = tvb_strsize(tvb, offset);
strptr = (guint8 *)se_alloc(size);
tvb_memcpy(tvb, strptr, offset, size);
if (lengthp)
*lengthp = size;
return strptr;
return (gchar*)wmem_strbuf_get_str(strbuf);
}
/* Looks for a stringz (NUL-terminated string) in tvbuff and copies
@ -2726,7 +2667,7 @@ tvb_bytes_to_str_punct(tvbuff_t *tvb, const gint offset, const gint len, const g
* tvbuff"), fetch BCD encoded digits from a tvbuff starting from either
* the low or high half byte, formating the digits according to an input digit set,
* if NUll a default digit set of 0-9 returning "?" for overdecadic digits will be used.
* A pointer to the EP allocated string will be returned.
* A pointer to the packet scope allocated string will be returned.
* Note a tvbuff content of 0xf is considered a 'filler' and will end the conversion.
*/
static dgt_set_t Dgt1_9_bcd = {
@ -2736,7 +2677,7 @@ static dgt_set_t Dgt1_9_bcd = {
}
};
const gchar *
tvb_bcd_dig_to_ep_str(tvbuff_t *tvb, const gint offset, const gint len, dgt_set_t *dgt, gboolean skip_first)
tvb_bcd_dig_to_wmem_packet_str(tvbuff_t *tvb, const gint offset, const gint len, dgt_set_t *dgt, gboolean skip_first)
{
int length;
guint8 octet;
@ -2755,7 +2696,7 @@ tvb_bcd_dig_to_ep_str(tvbuff_t *tvb, const gint offset, const gint len, dgt_set_
} else {
length = offset + len;
}
digit_str = (char *)ep_alloc((length - offset)*2+1);
digit_str = (char *)wmem_alloc(wmem_packet_scope(), (length - offset)*2+1);
while (t_offset < length) {

View File

@ -456,7 +456,7 @@ extern gchar *tvb_format_stringzpad_wsp(tvbuff_t *tvb, const gint offset, const
*
* Throws an exception if the tvbuff ends before the string does.
*
* tvb_get_string() returns a string allocated.
* tvb_get_string() returns a string allocated.
*
* tvb_get_unicode_string() Unicode (UTF-16) version of above.
*
@ -482,9 +482,7 @@ WS_DLL_PUBLIC guint8 *tvb_get_string_enc(wmem_allocator_t *scope, tvbuff_t *tvb,
* and return a pointer to the string. Also return the length of the
* string (including the terminating null) through a pointer.
*
* tvb_get_stringz() returns a string allocated by g_malloc() and therefore
* MUST be g_free() by the caller in order not to leak
* memory.
* tvb_get_stringz() returns a string
*
* tvb_get_stringz_enc() takes a string encoding as well, and converts to
* UTF-8 from the encoding (only UTF-8 and EBCDIC supported)
@ -494,28 +492,18 @@ WS_DLL_PUBLIC guint8 *tvb_get_string_enc(wmem_allocator_t *scope, tvbuff_t *tvb,
* freed once the next packet is dissected. It is slightly
* more efficient than the other routines.
*
* tvb_get_ephemeral_stringz() returns a string that does not need to be freed,
* instead it will automatically be freed once the next
* packet is dissected.
* tvb_get_unicode_stringz() Unicode (UTF-16) version of above
*
* tvb_get_ephemeral_stringz_enc() takes a string encoding as well, and
* converts to UTF-8 from the encoding (only UTF-8 and
* EBCDIC supported)
* packet is dissected.
*
* tvb_get_ephemeral_unicode_stringz() Unicode (UTF-16) version of above
*
* tvb_get_seasonal_stringz() returns a string that does not need to be freed,
* instead it will automatically be freed when a new capture
* or file is opened.
* If scope is set to NULL it is the user's responsibility to g_free()
* the memory allocated by tvb_memdup(). Otherwise memory is
* automatically freed when the scope lifetime is reached.
*/
WS_DLL_PUBLIC guint8 *tvb_get_g_stringz(tvbuff_t *tvb, const gint offset, gint *lengthp);
WS_DLL_PUBLIC guint8 *tvb_get_g_stringz_enc(tvbuff_t *tvb, const gint offset, gint *lengthp, const guint encoding);
WS_DLL_PUBLIC guint8 *tvb_get_stringz(wmem_allocator_t *scope, tvbuff_t *tvb, const gint offset, gint *lengthp);
WS_DLL_PUBLIC guint8 *tvb_get_stringz_enc(wmem_allocator_t *scope, tvbuff_t *tvb, const gint offset, gint *lengthp,
const guint encoding);
WS_DLL_PUBLIC const guint8 *tvb_get_const_stringz(tvbuff_t *tvb, const gint offset, gint *lengthp);
WS_DLL_PUBLIC guint8 *tvb_get_ephemeral_stringz(tvbuff_t *tvb, const gint offset, gint *lengthp);
WS_DLL_PUBLIC guint8 *tvb_get_ephemeral_stringz_enc(tvbuff_t *tvb, const gint offset, gint *lengthp, const guint encoding);
extern gchar *tvb_get_ephemeral_unicode_stringz(tvbuff_t *tvb, const gint offset, gint *lengthp, const guint encoding);
extern guint8 *tvb_get_seasonal_stringz(tvbuff_t *tvb, const gint offset, gint *lengthp);
WS_DLL_PUBLIC gchar *tvb_get_unicode_stringz(wmem_allocator_t *scope, tvbuff_t *tvb, const gint offset,
gint *lengthp, const guint encoding);
/** Looks for a stringz (NUL-terminated string) in tvbuff and copies
* no more than bufsize number of bytes, including terminating NUL, to buffer.
@ -656,7 +644,7 @@ typedef struct dgt_set_t
}
dgt_set_t;
WS_DLL_PUBLIC const gchar *tvb_bcd_dig_to_ep_str(tvbuff_t *tvb, const gint offset, const gint len, dgt_set_t *dgt, gboolean skip_first);
WS_DLL_PUBLIC const gchar *tvb_bcd_dig_to_wmem_packet_str(tvbuff_t *tvb, const gint offset, const gint len, dgt_set_t *dgt, gboolean skip_first);
/** Locate a sub-tvbuff within another tvbuff, starting at position
* 'haystack_offset'. Returns the index of the beginning of 'needle' within

View File

@ -1144,7 +1144,7 @@ WSLUA_METHOD TvbRange_stringz(lua_State* L) {
return 0;
}
lua_pushstring(L, (gchar*)tvb_get_ephemeral_stringz(tvbr->tvb->ws_tvb,tvbr->offset,NULL) );
lua_pushstring(L, (gchar*)tvb_get_stringz(wmem_packet_scope(),tvbr->tvb->ws_tvb,tvbr->offset,NULL) );
WSLUA_RETURN(1); /* The zero terminated string */
}
@ -1176,7 +1176,7 @@ static int TvbRange_ustringz_any(lua_State* L, gboolean little_endian) {
return 0;
}
lua_pushstring(L, (gchar*)tvb_get_ephemeral_unicode_stringz(tvbr->tvb->ws_tvb,tvbr->offset,&count,(little_endian ? ENC_LITTLE_ENDIAN : ENC_BIG_ENDIAN)) );
lua_pushstring(L, (gchar*)tvb_get_unicode_stringz(wmem_packet_scope(),tvbr->tvb->ws_tvb,tvbr->offset,&count,(little_endian ? ENC_LITTLE_ENDIAN : ENC_BIG_ENDIAN)) );
lua_pushinteger(L,count);
return 2; /* The zero terminated string, the length found in tvbr */

View File

@ -1807,7 +1807,7 @@ cmd_start(tvbuff_t *tvb, int offset, proto_tree *pt)
msglen = tvb_reported_length_remaining(tvb, offset);
offset = cmd_delete(tvb, offset, pt); /* decode the name */
if (offset < msglen + hdr_stuff) {
string = tvb_get_ephemeral_stringz(tvb, offset, &length);
string = tvb_get_stringz(wmem_packet_scope(), tvb, offset, &length);
if (length > 1) {
proto_tree_add_string(pt, hf_gryphon_start_arguments, tvb, offset,
length, string);