From 3805cb6f2f0190d81f2d68c7e83f3323da51209f Mon Sep 17 00:00:00 2001 From: Ali Sabil Date: Tue, 8 Oct 2019 22:17:53 +0200 Subject: [PATCH] mqtt: Dissect connect last will message as bytes MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The MQTT specification says "The Will Message defines the Application Message that is to be published to the Will Topic", Application Messages are defined as being application specific. Change-Id: I3fad1cb5f676b0232ba9e29af0d213b536ce4ef6 Reviewed-on: https://code.wireshark.org/review/34749 Petri-Dish: Stig Bjørlykke Tested-by: Petri Dish Buildbot Reviewed-by: Stig Bjørlykke --- epan/dissectors/packet-mqtt.c | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/epan/dissectors/packet-mqtt.c b/epan/dissectors/packet-mqtt.c index 69f3f6b427..ab29b3e864 100644 --- a/epan/dissectors/packet-mqtt.c +++ b/epan/dissectors/packet-mqtt.c @@ -514,6 +514,7 @@ static int hf_mqtt_will_topic_len = -1; static int hf_mqtt_will_topic = -1; static int hf_mqtt_will_msg_len = -1; static int hf_mqtt_will_msg = -1; +static int hf_mqtt_will_msg_text = -1; static int hf_mqtt_username_len = -1; static int hf_mqtt_username = -1; static int hf_mqtt_passwd_len = -1; @@ -1031,7 +1032,14 @@ static int dissect_mqtt(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, voi proto_tree_add_item_ret_uint(mqtt_tree, hf_mqtt_will_msg_len, tvb, offset, 2, ENC_BIG_ENDIAN, &mqtt_str_len); offset += 2; - proto_tree_add_item(mqtt_tree, hf_mqtt_will_msg, tvb, offset, mqtt_str_len, ENC_UTF_8|ENC_NA); + if (show_msg_as_text) + { + proto_tree_add_item(mqtt_tree, hf_mqtt_will_msg_text, tvb, offset, mqtt_str_len, ENC_UTF_8|ENC_NA); + } + else + { + proto_tree_add_item(mqtt_tree, hf_mqtt_will_msg, tvb, offset, mqtt_str_len, ENC_NA); + } offset += mqtt_str_len; } @@ -1413,6 +1421,10 @@ void proto_register_mqtt(void) FT_STRING, BASE_NONE, NULL, 0, NULL, HFILL }}, { &hf_mqtt_will_msg, + { "Will Message", "mqtt.willmsg", + FT_BYTES, BASE_NONE, NULL, 0, + NULL, HFILL }}, + { &hf_mqtt_will_msg_text, { "Will Message", "mqtt.willmsg", FT_STRING, BASE_NONE, NULL, 0, NULL, HFILL }},