From 3cc76c0adfd7f05075a641f7ea9206fac9d23280 Mon Sep 17 00:00:00 2001 From: firest Date: Tue, 1 Nov 2022 16:17:08 +0800 Subject: [PATCH] fix(coap): Ensure that the retain flag is a boolean value --- .../src/coap/handler/emqx_coap_pubsub_handler.erl | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/apps/emqx_gateway/src/coap/handler/emqx_coap_pubsub_handler.erl b/apps/emqx_gateway/src/coap/handler/emqx_coap_pubsub_handler.erl index 2e962a0bc..9c12e3343 100644 --- a/apps/emqx_gateway/src/coap/handler/emqx_coap_pubsub_handler.erl +++ b/apps/emqx_gateway/src/coap/handler/emqx_coap_pubsub_handler.erl @@ -121,7 +121,13 @@ apply_publish_opts(Msg, MQTTMsg) -> maps:fold( fun (<<"retain">>, V, Acc) -> - Val = erlang:binary_to_atom(V), + Val = + case emqx_misc:safe_to_existing_atom(V) of + {ok, true} -> + true; + _ -> + false + end, emqx_message:set_flag(retain, Val, Acc); (<<"expiry">>, V, Acc) -> Val = erlang:binary_to_integer(V),