Преглед изворни кода

Merge pull request #11074 from JimMoen/fix-share-sub-nl-protocol-error

fix: shared-sub with nl sub-option should cause protocol error
JimMoen пре 2 година
родитељ
комит
30ac6c4e48

+ 7 - 0
apps/emqx/src/emqx_packet.erl

@@ -270,6 +270,9 @@ check(#mqtt_packet_subscribe{topic_filters = TopicFilters}) ->
     try
     try
         validate_topic_filters(TopicFilters)
         validate_topic_filters(TopicFilters)
     catch
     catch
+        %% Known Specificed Reason Code
+        error:{error, RC} ->
+            {error, RC};
         error:_Error ->
         error:_Error ->
             {error, ?RC_TOPIC_FILTER_INVALID}
             {error, ?RC_TOPIC_FILTER_INVALID}
     end;
     end;
@@ -413,6 +416,10 @@ run_checks([Check | More], Packet, Options) ->
 validate_topic_filters(TopicFilters) ->
 validate_topic_filters(TopicFilters) ->
     lists:foreach(
     lists:foreach(
         fun
         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}) ->
             ({TopicFilter, _SubOpts}) ->
                 emqx_topic:validate(TopicFilter);
                 emqx_topic:validate(TopicFilter);
             (TopicFilter) ->
             (TopicFilter) ->

+ 15 - 0
apps/emqx/test/emqx_mqtt_protocol_v5_SUITE.erl

@@ -985,3 +985,18 @@ t_shared_subscriptions_client_terminates_when_qos_eq_2(Config) ->
 
 
     ?assertEqual(1, counters:get(CRef, 1)),
     ?assertEqual(1, counters:get(CRef, 1)),
     process_flag(trap_exit, false).
     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 - 0
changes/ce/fix-11074.en.md

@@ -0,0 +1 @@
+Fix to adhere to Protocol spec MQTT-5.0 [MQTT-3.8.3-4].