Merge pull request #7460 from lafirest/fix/empty_topic_4.3.14
fix(frame): forbidden empty topic in strict mode
This commit is contained in:
commit
1a302b1914
|
@ -17,6 +17,10 @@ File format:
|
|||
* In order to fix the execution order of exhook, e.g. before/after other plugins/modules,
|
||||
ExHook now supports user customizing emqx_hook execute priority.
|
||||
|
||||
### Bug fixes
|
||||
|
||||
* Prohibit empty topics in strict mode
|
||||
|
||||
## v4.3.13
|
||||
|
||||
### Important changes
|
||||
|
|
|
@ -265,7 +265,7 @@ parse_packet(#mqtt_packet_header{type = ?CONNACK}, <<AckFlags:8, ReasonCode:8, R
|
|||
|
||||
parse_packet(#mqtt_packet_header{type = ?PUBLISH, qos = QoS}, Bin,
|
||||
#{strict_mode := StrictMode, version := Ver}) ->
|
||||
{TopicName, Rest} = parse_utf8_string(Bin, StrictMode),
|
||||
{TopicName, Rest} = parse_topic_name(Bin, StrictMode),
|
||||
{PacketId, Rest1} = case QoS of
|
||||
?QOS_0 -> {undefined, Rest};
|
||||
_ -> parse_packet_id(Rest)
|
||||
|
@ -357,7 +357,7 @@ parse_will_message(Packet = #mqtt_packet_connect{will_flag = true,
|
|||
proto_ver = Ver},
|
||||
Bin, StrictMode) ->
|
||||
{Props, Rest} = parse_properties(Bin, Ver, StrictMode),
|
||||
{Topic, Rest1} = parse_utf8_string(Rest, StrictMode),
|
||||
{Topic, Rest1} = parse_topic_name(Rest, StrictMode),
|
||||
{Payload, Rest2} = parse_binary_data(Rest1),
|
||||
{Packet#mqtt_packet_connect{will_props = Props,
|
||||
will_topic = Topic,
|
||||
|
@ -524,6 +524,14 @@ parse_binary_data(Bin)
|
|||
when 2 > byte_size(Bin) ->
|
||||
error(malformed_binary_data_length).
|
||||
|
||||
parse_topic_name(Bin, false) ->
|
||||
parse_utf8_string(Bin, false);
|
||||
parse_topic_name(Bin, true) ->
|
||||
case parse_utf8_string(Bin, true) of
|
||||
{<<>>, _Rest} -> error(empty_topic_name);
|
||||
Result -> Result
|
||||
end.
|
||||
|
||||
%%--------------------------------------------------------------------
|
||||
%% Serialize MQTT Packet
|
||||
%%--------------------------------------------------------------------
|
||||
|
|
|
@ -162,6 +162,14 @@ t_parse_malformed_utf8_string(_) ->
|
|||
ParseState = emqx_frame:initial_parse_state(#{strict_mode => true}),
|
||||
?catch_error(utf8_string_invalid, emqx_frame:parse(MalformedPacket, ParseState)).
|
||||
|
||||
t_parse_empty_topic_name(_) ->
|
||||
Packet = <<48, 4, 0, 0, 0, 1>>,
|
||||
NormalState = emqx_frame:initial_parse_state(#{strict_mode => false}),
|
||||
?assertMatch({_, _}, emqx_frame:parse(Packet, NormalState)),
|
||||
|
||||
StrictState = emqx_frame:initial_parse_state(#{strict_mode => true}),
|
||||
?catch_error(empty_topic_name, emqx_frame:parse(Packet, StrictState)).
|
||||
|
||||
t_parse_frame_proxy_protocol(_) ->
|
||||
BinList = [ <<"PROXY TCP4 ">>, <<"PROXY TCP6 ">>, <<"PROXY UNKNOWN">>
|
||||
, <<"\r\n\r\n\0\r\nQUIT\n">>],
|
||||
|
|
Loading…
Reference in New Issue