From 2e13c4adb29bbd8a9cf01e4ceda93d65dd377c14 Mon Sep 17 00:00:00 2001 From: Peter Wu Date: Fri, 8 Feb 2019 18:08:20 +0100 Subject: [PATCH] mqtt: document UTF-8 requirement for topic_str If someone changes this in the future and the data is no longer valid UTF-8, then crashes can occur. Change-Id: I2b153d48ee1ef7093a5141001a391dd440c30e58 Ping-Bug: 14905 Reviewed-on: https://code.wireshark.org/review/31942 Reviewed-by: Peter Wu --- epan/dissectors/packet-mqtt.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/epan/dissectors/packet-mqtt.c b/epan/dissectors/packet-mqtt.c index ec1bda793a..ad27d939da 100644 --- a/epan/dissectors/packet-mqtt.c +++ b/epan/dissectors/packet-mqtt.c @@ -685,6 +685,7 @@ static void mqtt_user_decode_message(proto_tree *tree, proto_tree *mqtt_tree, pa if (message_decode_entry->topic_regex) { GMatchInfo *match_info = NULL; + /* DISSECTOR_ASSERT(g_utf8_validate(topic_str, -1, NULL)); */ g_regex_match(message_decode_entry->topic_regex, topic_str, (GRegexMatchFlags) 0, &match_info); match_found = g_match_info_matches(match_info); g_match_info_free(match_info); @@ -1078,6 +1079,7 @@ static int dissect_mqtt(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, voi proto_tree_add_item_ret_uint(mqtt_tree, hf_mqtt_topic_len, tvb, offset, 2, ENC_BIG_ENDIAN, &mqtt_str_len); offset += 2; + /* 'topic_regex' requires topic_str to be valid UTF-8. */ proto_tree_add_item_ret_string(mqtt_tree, hf_mqtt_topic, tvb, offset, mqtt_str_len, ENC_UTF_8|ENC_NA, wmem_epan_scope(), &topic_str); offset += mqtt_str_len;