Skip to content

Commit

Permalink
fix: shared-sub with nl sub-option should cause protocol error
Browse files Browse the repository at this point in the history
  • Loading branch information
JimMoen committed Jun 16, 2023
1 parent da164c5 commit 178711f
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 0 deletions.
7 changes: 7 additions & 0 deletions apps/emqx/src/emqx_packet.erl
Original file line number Diff line number Diff line change
Expand Up @@ -270,6 +270,9 @@ check(#mqtt_packet_subscribe{topic_filters = TopicFilters}) ->
try
validate_topic_filters(TopicFilters)
catch
%% Known Specificed Reason Code
error:{error, RC} ->
{error, RC};
error:_Error ->
{error, ?RC_TOPIC_FILTER_INVALID}
end;
Expand Down Expand Up @@ -413,6 +416,10 @@ run_checks([Check | More], Packet, Options) ->
validate_topic_filters(TopicFilters) ->
lists:foreach(
fun
%% Protocol Error and Should Disconnect
%% MQTT-5.0 [MQTT-3.8.3-4] and [MQTT-4.13.1-1]
({<<?SHARE, "/", _Rest/binary>>, #{nl := 1}}) ->
error({error, ?RC_PROTOCOL_ERROR});
({TopicFilter, _SubOpts}) ->
emqx_topic:validate(TopicFilter);
(TopicFilter) ->
Expand Down
15 changes: 15 additions & 0 deletions apps/emqx/test/emqx_mqtt_protocol_v5_SUITE.erl
Original file line number Diff line number Diff line change
Expand Up @@ -985,3 +985,18 @@ t_shared_subscriptions_client_terminates_when_qos_eq_2(Config) ->

?assertEqual(1, counters:get(CRef, 1)),
process_flag(trap_exit, false).

t_share_subscribe_no_local(Config) ->
ConnFun = ?config(conn_fun, Config),
process_flag(trap_exit, true),
ShareTopic = <<"$share/sharename/TopicA">>,

{ok, Client} = emqtt:start_link([{proto_ver, v5} | Config]),
{ok, _} = emqtt:ConnFun(Client),
%% MQTT-5.0 [MQTT-3.8.3-4] and [MQTT-4.13.1-1] (Disconnect)
case catch emqtt:subscribe(Client, #{}, [{ShareTopic, [{nl, true}, {qos, 1}]}]) of
{'EXIT', {Reason, _Stk}} ->
?assertEqual({disconnected, ?RC_PROTOCOL_ERROR, #{}}, Reason)
end,

process_flag(trap_exit, false).
1 change: 1 addition & 0 deletions changes/ce/fix-11074.en.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Fix Protocol spec MQTT-5.0 [MQTT-3.8.3-4].

0 comments on commit 178711f

Please sign in to comment.