Fix crash in emqx_acl_internal:filter/2

This commit is contained in:
周子博 2018-12-10 11:13:25 +08:00
parent 35e699e54e
commit ec2e289776
3 changed files with 8 additions and 4 deletions

View File

@ -47,7 +47,8 @@ compile({A, Who, Access, TopicFilters}) when ?ALLOW_DENY(A), ?PUBSUB(Access) ->
{A, compile(who, Who), Access, [compile(topic, Topic) || Topic <- TopicFilters]};
compile(Rule) ->
emqx_logger:error("[ACCESS_RULE] Malformed rule: ~p", [Rule]).
emqx_logger:error("[ACCESS_RULE] Malformed rule: ~p", [Rule]),
{error, bad_rule}.
compile(who, all) ->
all;

View File

@ -60,10 +60,12 @@ load_rules_from_file(AclFile) ->
ets:insert(?ACL_RULE_TAB, {all_rules, Terms}),
ok;
{error, Reason} ->
emqx_logger:error("[ACL_INTERNAL] Consult failed: ~p", [Reason]),
emqx_logger:error("[ACL_INTERNAL] Failed to read ~s: ~p", [AclFile, Reason]),
{error, Reason}
end.
filter(_PubSub, {error, _}) ->
false;
filter(_PubSub, {allow, all}) ->
true;
filter(_PubSub, {deny, all}) ->

View File

@ -355,7 +355,8 @@ compile_rule(_) ->
{deny, all, subscribe, [ [<<"$SYS">>, '#'], ['#'] ]} =
compile({deny, all, subscribe, ["$SYS/#", "#"]}),
{allow, all} = compile({allow, all}),
{deny, all} = compile({deny, all}).
{deny, all} = compile({deny, all}),
{error, bad_rule} = compile({test, malformed}).
match_rule(_) ->
User = #{client_id => <<"testClient">>, username => <<"TestUser">>, peername => {{127,0,0,1}, 2948}},