From 27ea011dd32ad6af3327ec9fe26b82d8b26e7596 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jo=C3=A3o=20Valverde?= Date: Fri, 25 Nov 2022 18:06:57 +0000 Subject: [PATCH] 802.11: Remove artificial string truncation The wmem_strbuf_new_label() creates a new buffer with a length limit in octets. With multibyte strings this is likely to generate invalid UTF-8 errors. Remove the artificial limit on the value size. The function proto_tree_add_string() sets the value, and truncating that to an arbitrary limit is not really correct. The display label will be truncated to a preset length by the UI. This mechanism uses ws_label_strcpy() and is designed to avoid the invalid truncation. While here use wmem_strbuf_get_str() instead of wmem_strbuf_finalize(). Accepted best practice is to let the scope free the memory. Removing the finalize call avoids an unnecessary realloc. Fixes #18653. --- epan/dissectors/packet-ieee80211.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/epan/dissectors/packet-ieee80211.c b/epan/dissectors/packet-ieee80211.c index 3839ccfbb5..3f0420dba5 100644 --- a/epan/dissectors/packet-ieee80211.c +++ b/epan/dissectors/packet-ieee80211.c @@ -15199,7 +15199,7 @@ dissect_he_feedback_matrix(proto_tree *tree, tvbuff_t *tvb, packet_info *pinfo, int ri, ci; int start_bit_offset = bit_offset; int start_offset = offset; - wmem_strbuf_t *angles = wmem_strbuf_new_label(pinfo->pool); + wmem_strbuf_t *angles = wmem_strbuf_new(pinfo->pool, NULL); if (nc == nr) /* If they are the same, reduce Nc by one */ nc -= 1; @@ -15224,7 +15224,7 @@ dissect_he_feedback_matrix(proto_tree *tree, tvbuff_t *tvb, packet_info *pinfo, /* Update this */ proto_tree_add_string(tree, hf, tvb, offset, ((start_bit_offset + 7) / 8) - start_offset, - wmem_strbuf_finalize(angles)); + wmem_strbuf_get_str(angles)); return bit_offset; }