dissector/mqtt: Rewrite the SUBSCRIBE payload size computation

- FIX: subtract the property length from the message length
- Replace the 'for' loop by a 'while' loop, now that the
  arithmetic is done before.

TODO: It's a protocol error (v5.0)/violation (v3.1.1) not to
include the payload in the SUBSCRIBE control packet. It would
be nice to display a "malformed packet legend" in such that
case.

Change-Id: I99ef3862aa19b3a31ea03d1c194e54f489674115
Signed-off-by: Flavio Santes <flavio.santes@1byt3.com>
Reviewed-on: https://code.wireshark.org/review/24313
Petri-Dish: Stig Bjørlykke <stig@bjorlykke.org>
Tested-by: Petri Dish Buildbot
Reviewed-by: Stig Bjørlykke <stig@bjorlykke.org>
This commit is contained in:
Flavio Santes 2017-11-08 22:55:30 -05:00 committed by Stig Bjørlykke
parent afb252355b
commit 4367855163
1 changed files with 9 additions and 2 deletions

View File

@ -839,12 +839,19 @@ static int dissect_mqtt(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, voi
proto_tree_add_item(mqtt_tree, hf_mqtt_msgid, tvb, offset, 2, ENC_BIG_ENDIAN);
offset += 2;
/* Subtract the Packet Id size to compute the Payload length */
mqtt_msg_len -= 2;
if (mqtt->runtime_proto_version == MQTT_PROTO_V50)
{
offset += dissect_mqtt_properties(tvb, mqtt_tree, offset);
guint32 mqtt_prop_offset = dissect_mqtt_properties(tvb, mqtt_tree, offset);
offset += mqtt_prop_offset;
/* Subtract the Property offset to compute the Payload length */
mqtt_msg_len -= mqtt_prop_offset;
}
for(mqtt_msg_len -= 2; mqtt_msg_len > 0;)
while (mqtt_msg_len > 0)
{
mqtt_str_len = tvb_get_ntohs(tvb, offset);
proto_tree_add_item(mqtt_tree, hf_mqtt_topic_len, tvb, offset, 2, ENC_BIG_ENDIAN);