Send DISCONNECT packet with reason code PROTOCOL_ERROR when topic is empty, add checks for topics

This commit is contained in:
周子博 2018-09-06 14:47:34 +08:00
parent 9029ee29d3
commit 42b3c9b4d6
2 changed files with 13 additions and 3 deletions

View File

@ -208,6 +208,9 @@ received(Packet = ?PACKET(Type), PState) ->
true ->
{Packet1, PState1} = preprocess_properties(Packet, PState),
process_packet(Packet1, inc_stats(recv, Type, PState1));
{'EXIT', {topic_filters_invalid, _Stacktrace}} ->
deliver({disconnect, ?RC_PROTOCOL_ERROR}, PState),
{error, topic_filters_invalid, PState};
{'EXIT', {Reason, _Stacktrace}} ->
deliver({disconnect, ?RC_MALFORMED_PACKET}, PState),
{error, Reason, PState}

View File

@ -184,9 +184,16 @@ parse(Topic = <<"$share/", _/binary>>, #{share := _Group}) ->
error({invalid_topic, Topic});
parse(<<"$queue/", Topic1/binary>>, Options) ->
parse(Topic1, maps:put(share, <<"$queue">>, Options));
parse(<<"$share/", Topic1/binary>>, Options) ->
[Group, Topic2] = binary:split(Topic1, <<"/">>),
{Topic2, maps:put(share, Group, Options)};
parse(Topic = <<"$share/", Topic1/binary>>, Options) ->
case binary:split(Topic1, <<"/">>) of
[<<>>] -> error({invalid_topic, Topic});
[_] -> error({invalid_topic, Topic});
[Group, Topic2] ->
case binary:match(Group, [<<"/">>, <<"+">>, <<"#">>]) of
nomatch -> error({invalid_topic, Topic});
_ -> {Topic2, maps:put(share, Group, Options)}
end
end;
parse(Topic, Options) ->
{Topic, Options}.