From 8302cac32992df665995608ec5c8e70ce6daaa4b Mon Sep 17 00:00:00 2001 From: Thales Macedo Garitezi Date: Thu, 10 Feb 2022 16:19:19 -0300 Subject: [PATCH 1/4] fix(channel): wrong case clause when alias is inexistent Fixes #6978 . --- src/emqx_channel.erl | 5 ++--- test/emqx_channel_SUITE.erl | 21 +++++++++++++++++++++ 2 files changed, 23 insertions(+), 3 deletions(-) diff --git a/src/emqx_channel.erl b/src/emqx_channel.erl index 20257911b..dc0c52598 100644 --- a/src/emqx_channel.erl +++ b/src/emqx_channel.erl @@ -1341,7 +1341,7 @@ process_alias(Packet = #mqtt_packet{ {ok, Topic} -> NPublish = Publish#mqtt_packet_publish{topic_name = Topic}, {ok, Packet#mqtt_packet{variable = NPublish}, Channel}; - false -> {error, ?RC_PROTOCOL_ERROR} + error -> {error, ?RC_PROTOCOL_ERROR} end; process_alias(#mqtt_packet{ @@ -1685,7 +1685,7 @@ run_hooks(Name, Args, Acc) -> -compile({inline, [find_alias/3, save_alias/4]}). -find_alias(_, _, undefined) -> false; +find_alias(_, _, undefined) -> error; find_alias(inbound, AliasId, _TopicAliases = #{inbound := Aliases}) -> maps:find(AliasId, Aliases); find_alias(outbound, Topic, _TopicAliases = #{outbound := Aliases}) -> @@ -1739,4 +1739,3 @@ flag(false) -> 0. set_field(Name, Value, Channel) -> Pos = emqx_misc:index_of(Name, record_info(fields, channel)), setelement(Pos+1, Channel, Value). - diff --git a/test/emqx_channel_SUITE.erl b/test/emqx_channel_SUITE.erl index a438fc79a..fd7da9f20 100644 --- a/test/emqx_channel_SUITE.erl +++ b/test/emqx_channel_SUITE.erl @@ -674,6 +674,13 @@ t_process_alias(_) -> {ok, #mqtt_packet{variable = #mqtt_packet_publish{topic_name = <<"t">>}}, _Chan} = emqx_channel:process_alias(#mqtt_packet{variable = Publish}, Channel). +t_process_alias_inexistent_alias(_) -> + Publish = #mqtt_packet_publish{topic_name = <<>>, properties = #{'Topic-Alias' => 1}}, + Channel = channel(), + ?assertEqual( + {error, ?RC_PROTOCOL_ERROR}, + emqx_channel:process_alias(#mqtt_packet{variable = Publish}, Channel)). + t_packing_alias(_) -> Packet1 = #mqtt_packet{variable = #mqtt_packet_publish{ topic_name = <<"x">>, @@ -710,6 +717,20 @@ t_packing_alias(_) -> #mqtt_packet{variable = #mqtt_packet_publish{topic_name = <<"z">>}}, channel())). +t_packing_alias_inexistent_alias(_) -> + Publish = #mqtt_packet_publish{topic_name = <<>>, properties = #{'Topic-Alias' => 1}}, + Channel = channel(), + Packet = #mqtt_packet{variable = Publish}, + ExpectedChannel = emqx_channel:set_field( + topic_aliases, + #{ inbound => #{} + , outbound => #{<<>> => 1} + }, + Channel), + ?assertEqual( + {Packet, ExpectedChannel}, + emqx_channel:packing_alias(Packet, Channel)). + t_check_pub_acl(_) -> ok = meck:expect(emqx_zone, enable_acl, fun(_) -> true end), Publish = ?PUBLISH_PACKET(?QOS_0, <<"t">>, 1, <<"payload">>), From acf3b8cbe90b73c80fe94fe082d232fa8918782a Mon Sep 17 00:00:00 2001 From: Thales Macedo Garitezi Date: Fri, 11 Feb 2022 17:18:29 -0300 Subject: [PATCH 2/4] chore(emqx): update appup --- src/emqx.app.src | 2 +- src/emqx.appup.src | 6 ++++-- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/src/emqx.app.src b/src/emqx.app.src index 1119deccb..1c6b05de4 100644 --- a/src/emqx.app.src +++ b/src/emqx.app.src @@ -1,7 +1,7 @@ {application, emqx, [{id, "emqx"}, {description, "EMQ X"}, - {vsn, "4.3.13"}, % strict semver, bump manually! + {vsn, "4.3.14"}, % strict semver, bump manually! {modules, []}, {registered, []}, {applications, [kernel,stdlib,gproc,gen_rpc,esockd,cowboy,sasl,os_mon]}, diff --git a/src/emqx.appup.src b/src/emqx.appup.src index df1b7c14e..cd5b02954 100644 --- a/src/emqx.appup.src +++ b/src/emqx.appup.src @@ -1,6 +1,7 @@ %% -*- mode: erlang -*- {VSN, - [{"4.3.12", + [{"4.3.13",[{load_module,emqx_channel,brutal_purge,soft_purge,[]}]}, + {"4.3.12", [{load_module,emqx_vm_mon,brutal_purge,soft_purge,[]}, {load_module,emqx_ctl,brutal_purge,soft_purge,[]}, {load_module,emqx_metrics,brutal_purge,soft_purge,[]}, @@ -335,7 +336,8 @@ {load_module,emqx_message,brutal_purge,soft_purge,[]}, {load_module,emqx_limiter,brutal_purge,soft_purge,[]}]}, {<<".*">>,[]}], - [{"4.3.12", + [{"4.3.13",[{load_module,emqx_channel,brutal_purge,soft_purge,[]}]}, + {"4.3.12", [{load_module,emqx_vm_mon,brutal_purge,soft_purge,[]}, {load_module,emqx_ctl,brutal_purge,soft_purge,[]}, {load_module,emqx_channel,brutal_purge,soft_purge,[]}, From b6e9043c497ac87c2014f7eb78a78921def84742 Mon Sep 17 00:00:00 2001 From: Thales Macedo Garitezi Date: Fri, 11 Feb 2022 17:22:08 -0300 Subject: [PATCH 3/4] chore(changelog): update changelog --- CHANGES-4.3.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/CHANGES-4.3.md b/CHANGES-4.3.md index 3e84d406d..2d7f13b0d 100644 --- a/CHANGES-4.3.md +++ b/CHANGES-4.3.md @@ -19,6 +19,8 @@ File format: ### Bug fixes +* Fix case where publishing to a non-existent topic alias would crash the connection [#6979] + ## v4.3.12 ### Important changes From 3f31df2297f6be6b143f120a7648c5e9123a5a2b Mon Sep 17 00:00:00 2001 From: Thales Macedo Garitezi Date: Mon, 14 Feb 2022 11:06:51 -0300 Subject: [PATCH 4/4] docs: add comment explaining application and release vsn discrepancy --- src/emqx.app.src | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/emqx.app.src b/src/emqx.app.src index 1c6b05de4..66ab590ca 100644 --- a/src/emqx.app.src +++ b/src/emqx.app.src @@ -1,6 +1,11 @@ {application, emqx, [{id, "emqx"}, {description, "EMQ X"}, + %% Note: this version is not the same as the release version! This + %% is simply the emqx `application' version, which is separate from + %% the emqx `release' version, which in turn is comprised of several + %% apps, one of which is this. See `emqx_release.hrl' for more + %% info. {vsn, "4.3.14"}, % strict semver, bump manually! {modules, []}, {registered, []},