diff options
author | Pascal Quantin <pascal.quantin@gmail.com> | 2013-09-22 20:04:35 +0000 |
---|---|---|
committer | Pascal Quantin <pascal.quantin@gmail.com> | 2013-09-22 20:04:35 +0000 |
commit | 102c452bcb8203b6cf0b0898f7badf3cb044b4d8 (patch) | |
tree | 05f19cbc24070c0074b4ab80a45d96f89e4dd914 /epan | |
parent | 1210a335abc6bf74068d3020252f25f714ff5ee2 (diff) |
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
Diffstat (limited to 'epan')
34 files changed, 127 insertions, 201 deletions
diff --git a/epan/dissectors/packet-afp.c b/epan/dissectors/packet-afp.c index e042b0e7ed..5ead62782b 100644 --- a/epan/dissectors/packet-afp.c +++ b/epan/dissectors/packet-afp.c @@ -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; diff --git a/epan/dissectors/packet-ansi_map.c b/epan/dissectors/packet-ansi_map.c index e957915ccf..4236a0673c 100644 --- a/epan/dissectors/packet-ansi_map.c +++ b/epan/dissectors/packet-ansi_map.c @@ -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; diff --git a/epan/dissectors/packet-dcerpc-spoolss.c b/epan/dissectors/packet-dcerpc-spoolss.c index 627c3d22ae..e967df36e5 100644 --- a/epan/dissectors/packet-dcerpc-spoolss.c +++ b/epan/dissectors/packet-dcerpc-spoolss.c @@ -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); diff --git a/epan/dissectors/packet-dmp.c b/epan/dissectors/packet-dmp.c index 3a2e4d35b8..7917f51c46 100644 --- a/epan/dissectors/packet-dmp.c +++ b/epan/dissectors/packet-dmp.c @@ -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; diff --git a/epan/dissectors/packet-dtn.c b/epan/dissectors/packet-dtn.c index 508b982dd1..a21e927b98 100644 --- a/epan/dissectors/packet-dtn.c +++ b/epan/dissectors/packet-dtn.c @@ -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*/ diff --git a/epan/dissectors/packet-exec.c b/epan/dissectors/packet-exec.c index 3c5e18c814..b86d50da63 100644 --- a/epan/dissectors/packet-exec.c +++ b/epan/dissectors/packet-exec.c @@ -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 diff --git a/epan/dissectors/packet-giop.c b/epan/dissectors/packet-giop.c index aaf7e73727..3102861a59 100644 --- a/epan/dissectors/packet-giop.c +++ b/epan/dissectors/packet-giop.c @@ -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); diff --git a/epan/dissectors/packet-glusterfs.c b/epan/dissectors/packet-glusterfs.c index f5624c804f..b4278e6fbd 100644 --- a/epan/dissectors/packet-glusterfs.c +++ b/epan/dissectors/packet-glusterfs.c @@ -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); diff --git a/epan/dissectors/packet-gsm_a_common.c b/epan/dissectors/packet-gsm_a_common.c index b38f563a12..1e363cc33b 100644 --- a/epan/dissectors/packet-gsm_a_common.c +++ b/epan/dissectors/packet-gsm_a_common.c @@ -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, diff --git a/epan/dissectors/packet-gsm_ipa.c b/epan/dissectors/packet-gsm_ipa.c index 305107f8bb..612f04debd 100644 --- a/epan/dissectors/packet-gsm_ipa.c +++ b/epan/dissectors/packet-gsm_ipa.c @@ -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) { diff --git a/epan/dissectors/packet-gtp.c b/epan/dissectors/packet-gtp.c index 7f2b4f8390..0fae98c641 100644 --- a/epan/dissectors/packet-gtp.c +++ b/epan/dissectors/packet-gtp.c @@ -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); diff --git a/epan/dissectors/packet-gtpv2.c b/epan/dissectors/packet-gtpv2.c index 814fdad659..a553b8c475 100644 --- a/epan/dissectors/packet-gtpv2.c +++ b/epan/dissectors/packet-gtpv2.c @@ -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; } diff --git a/epan/dissectors/packet-image-jfif.c b/epan/dissectors/packet-image-jfif.c index 1994e3befc..2065972ef5 100644 --- a/epan/dissectors/packet-image-jfif.c +++ b/epan/dissectors/packet-image-jfif.c @@ -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"); diff --git a/epan/dissectors/packet-isup.c b/epan/dissectors/packet-isup.c index 02203cd291..44db39b3d9 100644 --- a/epan/dissectors/packet-isup.c +++ b/epan/dissectors/packet-isup.c @@ -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); diff --git a/epan/dissectors/packet-lte-rrc.c b/epan/dissectors/packet-lte-rrc.c index 9e9ea13c77..2b8dbf20d5 100644 --- a/epan/dissectors/packet-lte-rrc.c +++ b/epan/dissectors/packet-lte-rrc.c @@ -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]); } diff --git a/epan/dissectors/packet-meta.c b/epan/dissectors/packet-meta.c index 2b110cff20..47c87fcfc9 100644 --- a/epan/dissectors/packet-meta.c +++ b/epan/dissectors/packet-meta.c @@ -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); diff --git a/epan/dissectors/packet-mip6.c b/epan/dissectors/packet-mip6.c index 641919059e..f85f2b6689 100644 --- a/epan/dissectors/packet-mip6.c +++ b/epan/dissectors/packet-mip6.c @@ -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; diff --git a/epan/dissectors/packet-mongo.c b/epan/dissectors/packet-mongo.c index 7e5d8e7dd1..442112bb0e 100644 --- a/epan/dissectors/packet-mongo.c +++ b/epan/dissectors/packet-mongo.c @@ -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; diff --git a/epan/dissectors/packet-pgsql.c b/epan/dissectors/packet-pgsql.c index e2b5f229b6..b0aa55d06c 100644 --- a/epan/dissectors/packet-pgsql.c +++ b/epan/dissectors/packet-pgsql.c @@ -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; diff --git a/epan/dissectors/packet-rsh.c b/epan/dissectors/packet-rsh.c index 7cf5ad8255..78c6cc5219 100644 --- a/epan/dissectors/packet-rsh.c +++ b/epan/dissectors/packet-rsh.c @@ -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 diff --git a/epan/dissectors/packet-sgsap.c b/epan/dissectors/packet-sgsap.c index 72e4b6f6e5..1e4109cc43 100644 --- a/epan/dissectors/packet-sgsap.c +++ b/epan/dissectors/packet-sgsap.c @@ -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). */ diff --git a/epan/dissectors/packet-smb-browse.c b/epan/dissectors/packet-smb-browse.c index a9e0ee0ed8..bf3fa1f8b3 100644 --- a/epan/dissectors/packet-smb-browse.c +++ b/epan/dissectors/packet-smb-browse.c @@ -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); diff --git a/epan/dissectors/packet-smb-common.c b/epan/dissectors/packet-smb-common.c index ce730b27d9..0d77f6b987 100644 --- a/epan/dissectors/packet-smb-common.c +++ b/epan/dissectors/packet-smb-common.c @@ -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 */ diff --git a/epan/dissectors/packet-smb.c b/epan/dissectors/packet-smb.c index 2426e6aa9e..1010c09315 100644 --- a/epan/dissectors/packet-smb.c +++ b/epan/dissectors/packet-smb.c @@ -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, diff --git a/epan/dissectors/packet-smpp.c b/epan/dissectors/packet-smpp.c index b44e0e6f2c..ad0563ad99 100644 --- a/epan/dissectors/packet-smpp.c +++ b/epan/dissectors/packet-smpp.c @@ -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) diff --git a/epan/dissectors/packet-spice.c b/epan/dissectors/packet-spice.c index 3968f75cac..0315088539 100644 --- a/epan/dissectors/packet-spice.c +++ b/epan/dissectors/packet-spice.c @@ -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; diff --git a/epan/dissectors/packet-teamspeak2.c b/epan/dissectors/packet-teamspeak2.c index 9295372c91..7f9a86e8a4 100644 --- a/epan/dissectors/packet-teamspeak2.c +++ b/epan/dissectors/packet-teamspeak2.c @@ -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; } diff --git a/epan/dissectors/packet-turbocell.c b/epan/dissectors/packet-turbocell.c index 8c5322b36b..4af4a21cd8 100644 --- a/epan/dissectors/packet-turbocell.c +++ b/epan/dissectors/packet-turbocell.c @@ -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)) { diff --git a/epan/dissectors/packet-wow.c b/epan/dissectors/packet-wow.c index 7002635240..4fb33f8b55 100644 --- a/epan/dissectors/packet-wow.c +++ b/epan/dissectors/packet-wow.c @@ -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; diff --git a/epan/dissectors/packet-wsp.c b/epan/dissectors/packet-wsp.c index 0d74154fbb..b66baa9269 100644 --- a/epan/dissectors/packet-wsp.c +++ b/epan/dissectors/packet-wsp.c @@ -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 \ * \ diff --git a/epan/proto.c b/epan/proto.c index f46431c28f..02371fe16c 100644 --- a/epan/proto.c +++ b/epan/proto.c @@ -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 { diff --git a/epan/tvbuff.c b/epan/tvbuff.c index 4bc6a400d1..85953b3013 100644 --- a/epan/tvbuff.c +++ b/epan/tvbuff.c @@ -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,78 +2048,34 @@ 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) -{ - return tvb_get_g_stringz_enc(tvb, offset, lengthp, ENC_UTF_8|ENC_NA); -} - -/* - * 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), ensure that - * the TVB is flat, and return a pointer to the string (in the TVB). - * Also return the length of the string (including the terminating null) - * through a pointer. - * - * As long as we aren't using composite TVBs, this saves the cycles used - * (often unnecessariliy) in allocating a buffer and copying the string into - * it. (If we do start using composite TVBs, we may want to replace this - * function with the _ephemeral versoin.) - */ -const guint8 * -tvb_get_const_stringz(tvbuff_t *tvb, const gint offset, gint *lengthp) -{ - guint size; - const guint8 *strptr; - - size = tvb_strsize(tvb, offset); - strptr = ensure_contiguous(tvb, offset, size); - if (lengthp) - *lengthp = size; - return strptr; -} - -/* - * 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) +tvb_get_stringz_enc(wmem_allocator_t *scope, tvbuff_t *tvb, const gint offset, gint *lengthp, const guint encoding) { guint size; guint8 *strptr; @@ -2141,7 +2096,7 @@ tvb_get_ephemeral_stringz_enc(tvbuff_t *tvb, const gint offset, gint *lengthp, c * 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); + strptr = tvb_get_stringz(scope, tvb, offset, lengthp); break; case ENC_UTF_8: @@ -2149,7 +2104,7 @@ tvb_get_ephemeral_stringz_enc(tvbuff_t *tvb, const gint offset, gint *lengthp, c * XXX - should map all invalid UTF-8 sequences * to a "substitute" UTF-8 character. */ - strptr = tvb_get_ephemeral_stringz(tvb, offset, lengthp); + strptr = tvb_get_stringz(scope, tvb, offset, lengthp); break; case ENC_UTF_16: @@ -2158,7 +2113,7 @@ tvb_get_ephemeral_stringz_enc(tvbuff_t *tvb, const gint offset, gint *lengthp, c * invalid characters and sequences to a "substitute" * UTF-8 character. */ - strptr = tvb_get_ephemeral_unicode_stringz(tvb, offset, lengthp, + strptr = tvb_get_unicode_stringz(scope, tvb, offset, lengthp, encoding & ENC_LITTLE_ENDIAN); break; @@ -2169,7 +2124,7 @@ tvb_get_ephemeral_stringz_enc(tvbuff_t *tvb, const gint offset, gint *lengthp, c * components of a UTF-16 surrogate pair) to a * "substitute" UTF-8 character. */ - strptr = tvb_get_ephemeral_unicode_stringz(tvb, offset, lengthp, + strptr = tvb_get_unicode_stringz(scope, tvb, offset, lengthp, encoding & ENC_LITTLE_ENDIAN); break; @@ -2180,7 +2135,7 @@ tvb_get_ephemeral_stringz_enc(tvbuff_t *tvb, const gint offset, gint *lengthp, c * XXX - multiple "dialects" of EBCDIC? */ size = tvb_strsize(tvb, offset); - strptr = (guint8 *)ep_alloc(size); + strptr = (guint8 *)wmem_alloc(scope, size); tvb_memcpy(tvb, strptr, offset, size); EBCDIC_to_ASCII(strptr, size); if (lengthp) @@ -2191,38 +2146,50 @@ tvb_get_ephemeral_stringz_enc(tvbuff_t *tvb, const gint offset, gint *lengthp, c return strptr; } -guint8 * -tvb_get_ephemeral_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), ensure that + * the TVB is flat, and return a pointer to the string (in the TVB). + * Also return the length of the string (including the terminating null) + * through a pointer. + * + * As long as we aren't using composite TVBs, this saves the cycles used + * (often unnecessariliy) in allocating a buffer and copying the string into + * it. (If we do start using composite TVBs, we may want to replace this + * function with the _ephemeral versoin.) + */ +const guint8 * +tvb_get_const_stringz(tvbuff_t *tvb, const gint offset, gint *lengthp) { - guint size; - guint8 *strptr; + guint size; + const guint8 *strptr; size = tvb_strsize(tvb, offset); - strptr = (guint8 *)ep_alloc(size); - tvb_memcpy(tvb, strptr, offset, size); + strptr = ensure_contiguous(tvb, 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) { diff --git a/epan/tvbuff.h b/epan/tvbuff.h index 90d2d10806..0646fcef38 100644 --- a/epan/tvbuff.h +++ b/epan/tvbuff.h @@ -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 diff --git a/epan/wslua/wslua_tvb.c b/epan/wslua/wslua_tvb.c index b0cef305da..9bca207ddb 100644 --- a/epan/wslua/wslua_tvb.c +++ b/epan/wslua/wslua_tvb.c @@ -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 */ |