From 2d10d6971df821a5188d5604cf9fa47707bf5abe Mon Sep 17 00:00:00 2001 From: Gilbert Wong Date: Sat, 8 Sep 2018 12:01:22 +0800 Subject: [PATCH 1/2] add pattern match for topic alias Prior to this change, it assume that topic_alias exists defaultly which may cause the unexpected bug This change fix this bug above --- src/emqx_protocol.erl | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/emqx_protocol.erl b/src/emqx_protocol.erl index 4602337eb..1dae228d7 100644 --- a/src/emqx_protocol.erl +++ b/src/emqx_protocol.erl @@ -650,9 +650,15 @@ check_publish(Packet, PState) -> check_pub_caps(#mqtt_packet{header = #mqtt_packet_header{qos = QoS, retain = Retain}, variable = #mqtt_packet_publish{ properties = Properties}}, #pstate{zone = Zone}) -> - #{'Topic-Alias' := TopicAlias} = Properties, + emqx_mqtt_caps:check_pub(Zone, #{qos => QoS, retain => Retain}); +check_pub_caps(#mqtt_packet{header = #mqtt_packet_header{qos = QoS, retain = Retain}, + variable = #mqtt_packet_publish{ + properties = #{'Topic-Alias' := TopicAlias} + }}, + #pstate{zone = Zone}) -> emqx_mqtt_caps:check_pub(Zone, #{qos => QoS, retain => Retain, topic_alias => TopicAlias}). + check_pub_acl(_Packet, #pstate{is_super = IsSuper, enable_acl = EnableAcl}) when IsSuper orelse (not EnableAcl) -> ok; From 78020de302a7a9e5a43f8cc45043ee88c03a2c78 Mon Sep 17 00:00:00 2001 From: Gilbert Wong Date: Sat, 8 Sep 2018 12:50:14 +0800 Subject: [PATCH 2/2] fix pattern match bu Prior to this change, when packet have topic alias, the check_pub_caps function could not be matched correctly This change fix this bug. --- src/emqx_protocol.erl | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/emqx_protocol.erl b/src/emqx_protocol.erl index 1dae228d7..49408d38e 100644 --- a/src/emqx_protocol.erl +++ b/src/emqx_protocol.erl @@ -647,16 +647,16 @@ check_publish(Packet, PState) -> run_check_steps([fun check_pub_caps/2, fun check_pub_acl/2], Packet, PState). -check_pub_caps(#mqtt_packet{header = #mqtt_packet_header{qos = QoS, retain = Retain}, - variable = #mqtt_packet_publish{ properties = Properties}}, - #pstate{zone = Zone}) -> - emqx_mqtt_caps:check_pub(Zone, #{qos => QoS, retain => Retain}); check_pub_caps(#mqtt_packet{header = #mqtt_packet_header{qos = QoS, retain = Retain}, variable = #mqtt_packet_publish{ properties = #{'Topic-Alias' := TopicAlias} }}, #pstate{zone = Zone}) -> - emqx_mqtt_caps:check_pub(Zone, #{qos => QoS, retain => Retain, topic_alias => TopicAlias}). + emqx_mqtt_caps:check_pub(Zone, #{qos => QoS, retain => Retain, topic_alias => TopicAlias}); +check_pub_caps(#mqtt_packet{header = #mqtt_packet_header{qos = QoS, retain = Retain}, + variable = #mqtt_packet_publish{ properties = Properties}}, + #pstate{zone = Zone}) -> + emqx_mqtt_caps:check_pub(Zone, #{qos => QoS, retain => Retain}). check_pub_acl(_Packet, #pstate{is_super = IsSuper, enable_acl = EnableAcl})