Kaynağa Gözat

Fix crash in emqx_acl_internal:filter/2

周子博 7 yıl önce
ebeveyn
işleme
ec2e289776

+ 2 - 1
src/emqx_access_rule.erl

@@ -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;

+ 4 - 2
src/emqx_acl_internal.erl

@@ -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}) ->

+ 2 - 1
test/emqx_access_SUITE.erl

@@ -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}},