Merge pull request #10315 from sstrigler/EMQX-8945-crash-for-bad-param-value-to-mqtt-delayed-messages-api-call

EMQX 8945 crash for bad param value to mqtt delayed messages api call
This commit is contained in:
Stefan Strigler 2023-04-05 13:44:22 +02:00 committed by GitHub
commit f3446c48f7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 8 additions and 7 deletions

View File

@ -52,7 +52,7 @@
-define(INVALID_NODE, 'INVALID_NODE'). -define(INVALID_NODE, 'INVALID_NODE').
api_spec() -> api_spec() ->
emqx_dashboard_swagger:spec(?MODULE). emqx_dashboard_swagger:spec(?MODULE, #{check_schema => true}).
paths() -> paths() ->
[ [
@ -202,9 +202,9 @@ delayed_message(get, #{bindings := #{node := NodeBin, msgid := HexId}}) ->
{200, Message#{payload => base64:encode(Payload)}} {200, Message#{payload => base64:encode(Payload)}}
end; end;
{error, not_found} -> {error, not_found} ->
{404, generate_http_code_map(not_found, Id)}; {404, generate_http_code_map(not_found, HexId)};
{badrpc, _} -> {badrpc, _} ->
{400, generate_http_code_map(invalid_node, Id)} {400, generate_http_code_map(invalid_node, NodeBin)}
end end
end end
); );
@ -271,19 +271,19 @@ generate_http_code_map(id_schema_error, Id) ->
#{ #{
code => ?MESSAGE_ID_SCHEMA_ERROR, code => ?MESSAGE_ID_SCHEMA_ERROR,
message => message =>
iolist_to_binary(io_lib:format("Message ID ~p schema error", [Id])) iolist_to_binary(io_lib:format("Message ID ~s schema error", [Id]))
}; };
generate_http_code_map(not_found, Id) -> generate_http_code_map(not_found, Id) ->
#{ #{
code => ?MESSAGE_ID_NOT_FOUND, code => ?MESSAGE_ID_NOT_FOUND,
message => message =>
iolist_to_binary(io_lib:format("Message ID ~p not found", [Id])) iolist_to_binary(io_lib:format("Message ID ~s not found", [Id]))
}; };
generate_http_code_map(invalid_node, Node) -> generate_http_code_map(invalid_node, Node) ->
#{ #{
code => ?INVALID_NODE, code => ?INVALID_NODE,
message => message =>
iolist_to_binary(io_lib:format("The node name ~p is invalid", [Node])) iolist_to_binary(io_lib:format("The node name ~s is invalid", [Node]))
}. }.
make_maybe(X, Error, Fun) -> make_maybe(X, Error, Fun) ->

View File

@ -1,7 +1,7 @@
%% -*- mode: erlang -*- %% -*- mode: erlang -*-
{application, emqx_modules, [ {application, emqx_modules, [
{description, "EMQX Modules"}, {description, "EMQX Modules"},
{vsn, "5.0.11"}, {vsn, "5.0.12"},
{modules, []}, {modules, []},
{applications, [kernel, stdlib, emqx, emqx_ctl]}, {applications, [kernel, stdlib, emqx, emqx_ctl]},
{mod, {emqx_modules_app, []}}, {mod, {emqx_modules_app, []}},

View File

@ -0,0 +1 @@
Fix crash checking `limit` and `page` parameters in `/mqtt/delayed/messages` API call.