wmem: Remove wmem_strbuf_new_label()

Only dissectors are using this function and there is no use case,
as far as I know, that requires its use. Any limitation of length
is imposed transparently by the UI backend.

This function is problematic because it is not Unicode aware and
will truncate a string on an arbitrary byte boundary for multibyte
strings.

Replace its use with a normal strbuf without a length limite and
remove the function because it is not useful and the ITEM_LABEL_LENGTH
parameter does not belong in wmem anyway.
This commit is contained in:
João Valverde 2022-11-25 18:32:41 +00:00
parent 93814ef740
commit 729ea56b46
24 changed files with 51 additions and 51 deletions

View File

@ -1106,7 +1106,7 @@ dissect_aprs( tvbuff_t *tvb, packet_info *pinfo, proto_tree *parent_tree, void *
dti = tvb_get_guint8( tvb, offset );
sb = wmem_strbuf_new_label(wmem_packet_scope());
sb = wmem_strbuf_create(wmem_packet_scope());
if (dti != '!')
wmem_strbuf_append(sb, val_to_str_ext_const(dti, &aprs_description_ext, ""));

View File

@ -3409,7 +3409,7 @@ decode_bgp_rd(wmem_allocator_t *pool, tvbuff_t *tvb, gint offset)
wmem_strbuf_t *strbuf;
rd_type = tvb_get_ntohs(tvb,offset);
strbuf = wmem_strbuf_new_label(pool);
strbuf = wmem_strbuf_create(pool);
switch (rd_type) {
case FORMAT_AS2_LOC:
@ -4390,7 +4390,7 @@ decode_mp_next_hop(tvbuff_t *tvb, proto_tree *tree, packet_info *pinfo, guint16
int length, offset = 0;
wmem_strbuf_t *strbuf;
strbuf = wmem_strbuf_new_label(pinfo->pool);
strbuf = wmem_strbuf_create(pinfo->pool);
/* BGP Multiprotocol Next Hop Principles
*
@ -7045,7 +7045,7 @@ decode_prefix_MP(proto_tree *tree, int hf_path_id, int hf_addr4, int hf_addr6,
}
/* snarf length */
plen = tvb_get_guint8(tvb, offset);
stack_strbuf = wmem_strbuf_new_label(pinfo->pool);
stack_strbuf = wmem_strbuf_create(pinfo->pool);
labnum = decode_MPLS_stack(tvb, offset + 1, stack_strbuf);
offset += (1 + labnum * 3);
@ -7116,7 +7116,7 @@ decode_prefix_MP(proto_tree *tree, int hf_path_id, int hf_addr4, int hf_addr6,
}
length = (plen + 7)/8;
comm_strbuf = wmem_strbuf_new_label(pinfo->pool);
comm_strbuf = wmem_strbuf_create(pinfo->pool);
switch (tvb_get_ntohs(tvb, offset + 1 + 4)) {
case BGP_EXT_COM_RT_AS2:
@ -7203,7 +7203,7 @@ decode_prefix_MP(proto_tree *tree, int hf_path_id, int hf_addr4, int hf_addr6,
case SAFNUM_LAB_VPNMULCAST:
case SAFNUM_LAB_VPNUNIMULC:
plen = tvb_get_guint8(tvb, offset);
stack_strbuf = wmem_strbuf_new_label(pinfo->pool);
stack_strbuf = wmem_strbuf_create(pinfo->pool);
labnum = decode_MPLS_stack(tvb, offset + 1, stack_strbuf);
offset += (1 + labnum * 3);
@ -7293,7 +7293,7 @@ decode_prefix_MP(proto_tree *tree, int hf_path_id, int hf_addr4, int hf_addr6,
}
/* snarf length */
plen = tvb_get_guint8(tvb, offset);
stack_strbuf = wmem_strbuf_new_label(pinfo->pool);
stack_strbuf = wmem_strbuf_create(pinfo->pool);
labnum = decode_MPLS_stack(tvb, offset + 1, stack_strbuf);
offset += (1 + labnum * 3);
@ -7402,7 +7402,7 @@ decode_prefix_MP(proto_tree *tree, int hf_path_id, int hf_addr4, int hf_addr6,
case SAFNUM_LAB_VPNMULCAST:
case SAFNUM_LAB_VPNUNIMULC:
plen = tvb_get_guint8(tvb, offset);
stack_strbuf = wmem_strbuf_new_label(pinfo->pool);
stack_strbuf = wmem_strbuf_create(pinfo->pool);
labnum = decode_MPLS_stack(tvb, offset + 1, stack_strbuf);
offset += (1 + labnum * 3);
@ -7538,7 +7538,7 @@ decode_prefix_MP(proto_tree *tree, int hf_path_id, int hf_addr4, int hf_addr6,
proto_tree_add_item(tree, hf_bgp_vplsbgp_labelblock_offset, tvb, offset+12, 2, ENC_BIG_ENDIAN);
proto_tree_add_item(tree, hf_bgp_vplsbgp_labelblock_size, tvb, offset+14, 2, ENC_BIG_ENDIAN);
stack_strbuf = wmem_strbuf_new_label(pinfo->pool);
stack_strbuf = wmem_strbuf_create(pinfo->pool);
decode_MPLS_stack(tvb, offset + 16, stack_strbuf);
proto_tree_add_string(tree, hf_bgp_vplsbgp_labelblock_base, tvb, offset+16, plen-14, wmem_strbuf_get_str(stack_strbuf));
@ -10011,7 +10011,7 @@ dissect_bgp_path_attr(proto_tree *subtree, tvbuff_t *tvb, guint16 path_attr_len,
q = o + i + aoff;
end = q + tlen;
wmem_strbuf_t *comm_strbuf;
comm_strbuf = wmem_strbuf_new_label(pinfo->pool);
comm_strbuf = wmem_strbuf_create(pinfo->pool);
while (q < end) {
guint32 ga, ldp1, ldp2;
ga = tvb_get_ntohl(tvb, q);
@ -10416,7 +10416,7 @@ dissect_bgp_path_attr(proto_tree *subtree, tvbuff_t *tvb, guint16 path_attr_len,
q = o + i + aoff;
end = q + tlen;
wmem_strbuf_t *dpath_strbuf;
dpath_strbuf = wmem_strbuf_new_label(pinfo->pool);
dpath_strbuf = wmem_strbuf_create(pinfo->pool);
guint8 dpath_len;
dpath_len = tvb_get_guint8(tvb, q);
proto_tree_add_item(subtree2, hf_bgp_d_path_length, tvb,

View File

@ -2158,7 +2158,7 @@ dissect_sdp_type(proto_tree *tree, packet_info *pinfo, tvbuff_t *tvb,
gint protocol_order;
wmem_strbuf_t *info_buf;
info_buf = wmem_strbuf_new_label(pinfo->pool);
info_buf = wmem_strbuf_create(pinfo->pool);
*pinfo_buf = info_buf;

View File

@ -125,7 +125,7 @@ dissect_dmx_chan(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, void* data
"0x%03x: %s",
"%3u: %s"
};
wmem_strbuf_t *chan_str = wmem_strbuf_new_label(pinfo->pool);
wmem_strbuf_t *chan_str = wmem_strbuf_create(pinfo->pool);
proto_item *item;
guint16 length,r,c,row_count;
guint8 v;

View File

@ -2256,7 +2256,7 @@ dissect_dns_answer(tvbuff_t *tvb, int offsetx, int dns_data_offset,
int port_num;
int i;
proto_item *ti_wks;
wmem_strbuf_t *bitnames = wmem_strbuf_new_label(wmem_packet_scope());
wmem_strbuf_t *bitnames = wmem_strbuf_create(wmem_packet_scope());
wks_addr = tvb_ip_to_str(pinfo->pool, tvb, cur_offset);
col_append_fstr(pinfo->cinfo, COL_INFO, " %s", wks_addr);

View File

@ -255,7 +255,7 @@ dissect_enttec_dmx_data(tvbuff_t *tvb, guint offset, proto_tree *tree)
si = proto_item_add_subtree(hi, ett_enttec);
row_count = (ui/global_disp_col_count) + ((ui%global_disp_col_count) == 0 ? 0 : 1);
dmx_epstr = wmem_strbuf_new_label(wmem_packet_scope());
dmx_epstr = wmem_strbuf_create(wmem_packet_scope());
for (r=0; r < row_count;r++) {
for (c=0;(c < global_disp_col_count) && (((r*global_disp_col_count)+c) < ui);c++) {
if ((global_disp_col_count > 1) && (c % (global_disp_col_count/2)) == 0) {

View File

@ -1704,7 +1704,7 @@ dissect_channelised_ex_header(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tr
guint8 vc_size = (guint8)((hdr >> 16) & 0xFF);
guint8 line_rate = (guint8)((hdr >> 8) & 0xFF);
sdh_g707_format_t g707_format;
wmem_strbuf_t *vc_id_string = wmem_strbuf_new_label(pinfo->pool);
wmem_strbuf_t *vc_id_string = wmem_strbuf_create(pinfo->pool);
channelised_fill_sdh_g707_format(&g707_format, vc_id, vc_size, line_rate);
channelised_fill_vc_id_string(vc_id_string, &g707_format);

View File

@ -513,7 +513,7 @@ read_number(unsigned int *offset, tvbuff_t *tvb, proto_tree *etch_tree,
const gchar *symbol = NULL;
guint32 hash = 0;
gbl_symbol_buffer = wmem_strbuf_new_label(wmem_packet_scope()); /* no symbol found yet */
gbl_symbol_buffer = wmem_strbuf_create(wmem_packet_scope()); /* no symbol found yet */
if (byteLength == 4) {
hash = tvb_get_ntohl(tvb, *offset);
symbol = try_val_to_str_ext(hash, gbl_symbols_vs_ext);
@ -667,7 +667,7 @@ get_column_info(tvbuff_t *tvb)
int my_offset = 0;
/* We've a full PDU: 8 bytes + pdu_packetlen bytes */
result_buf = wmem_strbuf_new_label(wmem_packet_scope());
result_buf = wmem_strbuf_create(wmem_packet_scope());
my_offset += (4 + 4 + 1); /* skip Magic, Length, Version */

View File

@ -132,7 +132,7 @@ dissect_fw1(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, void* data _U_)
static const char fw1_header[] = "FW1 Monitor";
ethertype_data_t ethertype_data;
header = wmem_strbuf_new_label(pinfo->pool);
header = wmem_strbuf_create(pinfo->pool);
wmem_strbuf_append(header, fw1_header);
/* Make entries in Protocol column and Info column on summary display */

View File

@ -4377,7 +4377,7 @@ dissect_icmpv6(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, void *data)
case ICMP6_ND_NEIGHBOR_ADVERT: /* Neighbor Advertisement (136) */
{
guint32 na_flags;
wmem_strbuf_t *flags_strbuf = wmem_strbuf_new_label(pinfo->pool);
wmem_strbuf_t *flags_strbuf = wmem_strbuf_create(pinfo->pool);
static int * const nd_na_flags[] = {
&hf_icmpv6_nd_na_flag_r,
&hf_icmpv6_nd_na_flag_s,

View File

@ -1665,7 +1665,7 @@ static int dissect_iec60870_asdu(tvbuff_t *tvb, packet_info *pinfo, proto_tree *
it104 = proto_tree_add_item(tree, proto_iec60870_asdu, tvb, offset, -1, ENC_NA);
it104tree = proto_item_add_subtree(it104, ett_asdu);
res = wmem_strbuf_new_label(pinfo->pool);
res = wmem_strbuf_create(pinfo->pool);
/* Type identification */
asduh.TypeId = tvb_get_guint8(tvb, offset);
@ -2074,7 +2074,7 @@ static int dissect_iec60870_104(tvbuff_t *tvb, packet_info *pinfo, proto_tree *t
it104 = proto_tree_add_item(tree, proto_iec60870_104, tvb, 0, -1, ENC_NA);
it104tree = proto_item_add_subtree(it104, ett_apci);
res = wmem_strbuf_new_label(pinfo->pool);
res = wmem_strbuf_create(pinfo->pool);
Start = 0;
for (Off = 0; Off <= TcpLen - 2; Off++) {

View File

@ -8906,7 +8906,7 @@ dissect_dscp_policy_response(tvbuff_t *tvb, packet_info *pinfo,
{
int start_offset = offset;
guint8 count;
wmem_strbuf_t *status_buf = wmem_strbuf_new_label(pinfo->pool);
wmem_strbuf_t *status_buf = wmem_strbuf_create(pinfo->pool);
int i;
proto_tree_add_bitmask(tree, tvb, offset,

View File

@ -1308,9 +1308,9 @@ static int dissect_jxta_message(tvbuff_t * tvb, packet_info * pinfo, proto_tree
return -needed;
}
src_addr = wmem_strbuf_new_label(pinfo->pool);
src_addr = wmem_strbuf_create(pinfo->pool);
wmem_strbuf_append(src_addr, address_to_str(pinfo->pool, &pinfo->src));
dst_addr = wmem_strbuf_new_label(pinfo->pool);
dst_addr = wmem_strbuf_create(pinfo->pool);
wmem_strbuf_append(dst_addr, address_to_str(pinfo->pool, &pinfo->dst));
/* append the port if appropriate */

View File

@ -120,7 +120,7 @@ static int dissect_miop (tvbuff_t * tvb, packet_info * pinfo, proto_tree * tree,
guint32 unique_id_len;
wmem_strbuf_t *flags_strbuf = wmem_strbuf_new_label(pinfo->pool);
wmem_strbuf_t *flags_strbuf = wmem_strbuf_create(pinfo->pool);
wmem_strbuf_append(flags_strbuf, "none");
if (!dissect_miop_heur_check(tvb, pinfo, tree, data))

View File

@ -237,7 +237,7 @@ dissect_netanalyzer_common(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
proto_tree_add_bitmask(netanalyzer_header_tree, tvb, 0, hf_netanalyzer_status, ett_netanalyzer_status, hfx_netanalyzer_status, ENC_LITTLE_ENDIAN);
strbuf = wmem_strbuf_new_label(pinfo->pool);
strbuf = wmem_strbuf_create(pinfo->pool);
for (idx = 0; idx < 8; idx++)
{
if (packet_status & (1 << idx))

View File

@ -1057,7 +1057,7 @@ static int dissect_p_mul (tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, v
break;
case Ack_PDU:
message_id_list = wmem_strbuf_new_label(pinfo->pool);
message_id_list = wmem_strbuf_create(pinfo->pool);
for (i = 0; i < count; i++) {
/* Ack Info Entry */

View File

@ -3367,7 +3367,7 @@ static void append_status_info(packet_info *pinfo,
gchar * writerId = NULL;
gchar * disposeFlag = NULL;
gchar * unregisterFlag = NULL;
wmem_strbuf_t *buffer = wmem_strbuf_new_label(wmem_packet_scope());
wmem_strbuf_t *buffer = wmem_strbuf_create(wmem_packet_scope());
switch(writer_id) {
case ENTITYID_PARTICIPANT:
@ -5231,7 +5231,7 @@ static gint rtps_util_add_typecode(proto_tree *tree, tvbuff_t *tvb, gint offset,
/* Array print */
if (arr_dimension != NULL) {
/* Printing an array */
wmem_strbuf_t *dim_str = wmem_strbuf_new_label(wmem_packet_scope());
wmem_strbuf_t *dim_str = wmem_strbuf_create(wmem_packet_scope());
for (i = 0; i < MAX_ARRAY_DIMENSION; ++i) {
if (arr_dimension[i] != 0) {
wmem_strbuf_append_printf(dim_str, "[%d]", arr_dimension[i]);
@ -6042,8 +6042,8 @@ static int rtps_util_add_bitmap(proto_tree *tree,
gboolean show_analysis) {
gint32 num_bits;
guint32 data;
wmem_strbuf_t *temp_buff = wmem_strbuf_new_label(wmem_packet_scope());
wmem_strbuf_t *analysis_buff = wmem_strbuf_new_label(wmem_packet_scope());
wmem_strbuf_t *temp_buff = wmem_strbuf_create(wmem_packet_scope());
wmem_strbuf_t *analysis_buff = wmem_strbuf_create(wmem_packet_scope());
gint i, j, idx;
gchar *last_one;
proto_item *ti = NULL, *ti_tree = NULL;
@ -6141,7 +6141,7 @@ static int rtps_util_add_fragment_number_set(proto_tree *tree, packet_info *pinf
guint64 base;
gint32 num_bits;
guint32 data;
wmem_strbuf_t *temp_buff = wmem_strbuf_new_label(wmem_packet_scope());
wmem_strbuf_t *temp_buff = wmem_strbuf_create(wmem_packet_scope());
gchar *last_one;
int i, j, idx;
proto_item *ti;

View File

@ -3179,7 +3179,7 @@ s7comm_decode_pistart_parameters(tvbuff_t *tvb,
guint8 i;
guint8 len;
wmem_strbuf_t *args_buf;
args_buf = wmem_strbuf_new_label(pinfo->pool);
args_buf = wmem_strbuf_create(pinfo->pool);
for (i = 0; i < nfields; i++) {
len = tvb_get_guint8(tvb, offset);

View File

@ -514,7 +514,7 @@ static void dissect_dereg_req(tvbuff_t *tvb, packet_info *pinfo, proto_tree *pay
proto_tree *dereg_req_data;
guint8 reason_flag;
static gboolean first_flag = TRUE;
wmem_strbuf_t *reasonflags_strbuf = wmem_strbuf_new_label(pinfo->pool);
wmem_strbuf_t *reasonflags_strbuf = wmem_strbuf_create(pinfo->pool);
static const gchar *fstr[] = {"No Reason", "Learned & Purposeful" };
dereg_req_data = proto_tree_add_subtree(pay_load, tvb, offset, -1, ett_sasp_dereg_req_sz, NULL, "DeReg Request");

View File

@ -1983,7 +1983,7 @@ decode_lcd_line_cmd(proto_tree *tree, tvbuff_t *tvb, packet_info *pinfo,
if (!ua3g_body_tree)
return;
strbuf = wmem_strbuf_new_label(pinfo->pool);
strbuf = wmem_strbuf_create(pinfo->pool);
wmem_strbuf_append_printf(strbuf, "\"%s\"", tvb_format_text(pinfo->pool, tvb, offset + 2, length - 2));
@ -2803,7 +2803,7 @@ decode_audio_config(proto_tree *tree, tvbuff_t *tvb, packet_info *pinfo,
int j;
int device_index = 0;
strbuf = wmem_strbuf_new_label(pinfo->pool);
strbuf = wmem_strbuf_create(pinfo->pool);
while (length > 0) {

View File

@ -236,7 +236,7 @@ dissect_flags(tvbuff_t *tvb, int offset, proto_tree *tree)
if (flags != 0)
{
wmem_strbuf_t *strbuf = wmem_strbuf_new_label(wmem_packet_scope());
wmem_strbuf_t *strbuf = wmem_strbuf_create(wmem_packet_scope());
if (flags & VXI11_CORE_FLAG_WAITLOCK)
{
@ -281,7 +281,7 @@ dissect_reason(tvbuff_t *tvb, int offset, proto_tree *tree)
if (reason != 0)
{
wmem_strbuf_t *strbuf = wmem_strbuf_new_label(wmem_packet_scope());
wmem_strbuf_t *strbuf = wmem_strbuf_create(wmem_packet_scope());
if (reason & VXI11_CORE_REASON_REQCNT)
{

View File

@ -1546,18 +1546,18 @@ dissect_nt_sid(tvbuff_t *tvb, int offset, proto_tree *parent_tree,
offset++;
}
sid_in_dec_str = wmem_strbuf_new_label(wmem_packet_scope());
sid_in_dec_str = wmem_strbuf_create(wmem_packet_scope());
wmem_strbuf_append_printf (sid_in_dec_str, "S-%u-%" PRIu64, revision, authority);
/* If sid_display_hex is set, sid_in_dec_str is still needed for
looking up well-known SIDs*/
if (sid_display_hex) {
sid_in_hex_str = wmem_strbuf_new_label(wmem_packet_scope());
sid_in_hex_str = wmem_strbuf_create(wmem_packet_scope());
wmem_strbuf_append_printf (sid_in_hex_str, "S-%x-%" PRIx64, revision, authority);
}
wkwn_sid1_str = wmem_strbuf_new_label(wmem_packet_scope());
label_str = wmem_strbuf_new_label(wmem_packet_scope());
wkwn_sid1_str = wmem_strbuf_create(wmem_packet_scope());
label_str = wmem_strbuf_create(wmem_packet_scope());
if (strcmp(wmem_strbuf_get_str(sid_in_dec_str), "S-1-16")==0)
S_1_16 = TRUE;
@ -1582,9 +1582,9 @@ dissect_nt_sid(tvbuff_t *tvb, int offset, proto_tree *parent_tree,
sa_offset = offset;
sa_str = wmem_strbuf_new_label(wmem_packet_scope());
wkwn_sid2_str = wmem_strbuf_new_label(wmem_packet_scope());
domain_str = wmem_strbuf_new_label(wmem_packet_scope());
sa_str = wmem_strbuf_create(wmem_packet_scope());
wkwn_sid2_str = wmem_strbuf_create(wmem_packet_scope());
domain_str = wmem_strbuf_create(wmem_packet_scope());
/* Build the sub-authorities and full SID strings */
for(i=1; i<num_auth+1; i++) {

View File

@ -1319,7 +1319,7 @@ static void colorFlags(tvbuff_t *tvb, int *offsetp, proto_tree *t)
if (do_red_green_blue) {
int sep = FALSE;
wmem_strbuf_t *buffer = wmem_strbuf_new_label(wmem_packet_scope());
wmem_strbuf_t *buffer = wmem_strbuf_create(wmem_packet_scope());
wmem_strbuf_append(buffer, "flags: ");
if (do_red_green_blue & 0x1) {
@ -1517,7 +1517,7 @@ static void listOfColorItem(tvbuff_t *tvb, int *offsetp, proto_tree *t, int hf,
wmem_strbuf_t *buffer;
const char *sep;
buffer=wmem_strbuf_new_label(wmem_packet_scope());
buffer=wmem_strbuf_create(wmem_packet_scope());
wmem_strbuf_append(buffer, "colorItem ");
red = tvb_get_guint16(tvb, *offsetp + 4, byte_order);
green = tvb_get_guint16(tvb, *offsetp + 6, byte_order);

View File

@ -58,14 +58,14 @@ wmem_strbuf_sized_new(wmem_allocator_t *allocator,
size_t alloc_size, size_t max_size)
G_GNUC_MALLOC;
#define wmem_strbuf_new_label(ALLOCATOR) \
wmem_strbuf_sized_new((ALLOCATOR), 0, ITEM_LABEL_LENGTH)
WS_DLL_PUBLIC
wmem_strbuf_t *
wmem_strbuf_new(wmem_allocator_t *allocator, const gchar *str)
G_GNUC_MALLOC;
#define wmem_strbuf_create(allocator) \
wmem_strbuf_new(allocator, "")
WS_DLL_PUBLIC
wmem_strbuf_t *
wmem_strbuf_new_len(wmem_allocator_t *allocator, const gchar *str, size_t len)