From 2be97a24ddd780f6fd8da979dd3f952de368f259 Mon Sep 17 00:00:00 2001 From: zhongwencool Date: Mon, 21 Mar 2022 09:19:28 +0800 Subject: [PATCH] fix: subscribe api crash with bad qos. --- CHANGES-4.3.md | 1 + apps/emqx_management/include/emqx_mgmt.hrl | 1 + apps/emqx_management/src/emqx_management.app.src | 2 +- apps/emqx_management/src/emqx_mgmt_api_pubsub.erl | 2 ++ 4 files changed, 5 insertions(+), 1 deletion(-) diff --git a/CHANGES-4.3.md b/CHANGES-4.3.md index d0ad3d6c1..a2d7f4edc 100644 --- a/CHANGES-4.3.md +++ b/CHANGES-4.3.md @@ -48,6 +48,7 @@ File format: * Prompt user how to change the dashboard's initial default password when emqx start. * Fix errno=13 'Permission denied' Cannot create FIFO boot error in Amazon Linux 2022 (el8 package) * Fix user or appid created, name only allow `^[A-Za-z]+[A-Za-z0-9-_]*$` +* Fix subscribe http api crash by bad_qos `/mqtt/subscribe`,`/mqtt/subscribe_batch`. ## v4.3.12 ### Important changes diff --git a/apps/emqx_management/include/emqx_mgmt.hrl b/apps/emqx_management/include/emqx_mgmt.hrl index 6d510ed0c..3b54e313f 100644 --- a/apps/emqx_management/include/emqx_mgmt.hrl +++ b/apps/emqx_management/include/emqx_mgmt.hrl @@ -31,5 +31,6 @@ -define(ERROR13, 113). %% User already exist -define(ERROR14, 114). %% OldPassword error -define(ERROR15, 115). %% bad topic +-define(ERROR16, 116). %% bad QoS -define(VERSIONS, ["4.0", "4.1", "4.2", "4.3"]). \ No newline at end of file diff --git a/apps/emqx_management/src/emqx_management.app.src b/apps/emqx_management/src/emqx_management.app.src index 64f44637a..e203c7a56 100644 --- a/apps/emqx_management/src/emqx_management.app.src +++ b/apps/emqx_management/src/emqx_management.app.src @@ -1,6 +1,6 @@ {application, emqx_management, [{description, "EMQ X Management API and CLI"}, - {vsn, "4.3.12"}, % strict semver, bump manually! + {vsn, "4.3.13"}, % strict semver, bump manually! {modules, []}, {registered, [emqx_management_sup]}, {applications, [kernel,stdlib,minirest]}, diff --git a/apps/emqx_management/src/emqx_mgmt_api_pubsub.erl b/apps/emqx_management/src/emqx_mgmt_api_pubsub.erl index 53ca022bb..31b6d36f1 100644 --- a/apps/emqx_management/src/emqx_mgmt_api_pubsub.erl +++ b/apps/emqx_management/src/emqx_mgmt_api_pubsub.erl @@ -151,6 +151,8 @@ do_subscribe(ClientId, _Topics, _QoS) when not is_binary(ClientId) -> {ok, ?ERROR8, <<"bad clientid: must be string">>}; do_subscribe(_ClientId, [], _QoS) -> {ok, ?ERROR15, bad_topic}; +do_subscribe(_ClientId, _Topic, QoS) when QoS =/= 0 andalso QoS =/= 1 andalso QoS =/= 2 -> + {ok, ?ERROR16, bad_qos}; do_subscribe(ClientId, Topics, QoS) -> TopicTable = parse_topic_filters(Topics, QoS), case emqx_mgmt:subscribe(ClientId, TopicTable) of