From fbf403de00642d477d3d2e637c954e8c58fe1d19 Mon Sep 17 00:00:00 2001 From: Gerald Combs Date: Tue, 15 Feb 2022 12:32:25 -0800 Subject: [PATCH] epan: Always set our proto_item_fill_label label. Make sure label_str is valid, and print a warning if it's NULL. Try to fix ``` /builds/wireshark/wireshark/epan/dissectors/packet-diameter.c: 1174 in integer32_avp() 1168 gint length = tvb_reported_length(tvb); 1169 if (length == 4) { 1170 if (c->tree) { 1171 pi= proto_tree_add_item(c->tree, a->hf_value, tvb, 0, length, ENC_BIG_ENDIAN); 1172 label = (char *)wmem_alloc(wmem_packet_scope(), ITEM_LABEL_LENGTH+1); 1173 proto_item_fill_label(PITEM_FINFO(pi), label); >>> CID 1499506: Memory - illegal accesses (STRING_NULL) >>> Passing unterminated string "label" to "strstr", which expects a null-terminated string. 1174 label = strstr(label,": ")+2; 1175 } 1176 } 1177 else { 1178 pi = proto_tree_add_bytes_format(c->tree, hf_diameter_avp_data_wrong_length, 1179 tvb, 0, length, NULL, ``` --- epan/proto.c | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/epan/proto.c b/epan/proto.c index db404150ae..b704df6e17 100644 --- a/epan/proto.c +++ b/epan/proto.c @@ -9039,10 +9039,14 @@ proto_item_fill_label(field_info *fi, gchar *label_str) char *addr_str; char *tmp; + if (!label_str) { + ws_warning("NULL label_str passed to proto_item_fill_label."); + return; + } + + label_str[0]= '\0'; + if (!fi) { - if (label_str) - label_str[0]= '\0'; - /* XXX: Check validity of hfinfo->type */ return; }