diff options
author | Simon MacMullen <simon@rabbitmq.com> | 2013-01-16 17:51:46 +0000 |
---|---|---|
committer | Simon MacMullen <simon@rabbitmq.com> | 2013-01-16 17:51:46 +0000 |
commit | dd9ff7ba5a9593eaa8204fd07e776d52127e562f (patch) | |
tree | d6f50a8f06281553c7ac55e0d8636b829d94238e /src/rabbit_policy.erl | |
parent | f7d65da018f9b7aab3d51f0a74f801ed26966fe4 (diff) | |
download | rabbitmq-server-dd9ff7ba5a9593eaa8204fd07e776d52127e562f.tar.gz |
Prevent explosion if someone passes a list.bug25401
Diffstat (limited to 'src/rabbit_policy.erl')
-rw-r--r-- | src/rabbit_policy.erl | 13 |
1 files changed, 9 insertions, 4 deletions
diff --git a/src/rabbit_policy.erl b/src/rabbit_policy.erl index 2c997f16..fa13c5dd 100644 --- a/src/rabbit_policy.erl +++ b/src/rabbit_policy.erl @@ -218,10 +218,13 @@ validation(_Name, Terms) when is_list(Terms) -> rabbit_registry:lookup_all(policy_validator)), [] = dups(Keys), %% ASSERTION Validators = lists:zipwith(fun (M, K) -> {M, a2b(K)} end, Modules, Keys), - {TermKeys, _} = lists:unzip(Terms), - case dups(TermKeys) of - [] -> validation0(Validators, Terms); - Dup -> {error, "~p duplicate keys not allowed", [Dup]} + case is_proplist(Terms) of + true -> {TermKeys, _} = lists:unzip(Terms), + case dups(TermKeys) of + [] -> validation0(Validators, Terms); + Dup -> {error, "~p duplicate keys not allowed", [Dup]} + end; + false -> {error, "definition must be a dictionary: ~p", [Terms]} end; validation(_Name, Term) -> {error, "parse error while reading policy: ~p", [Term]}. @@ -249,3 +252,5 @@ validation0(Validators, Terms) -> a2b(A) -> list_to_binary(atom_to_list(A)). dups(L) -> L -- lists:usort(L). + +is_proplist(L) -> length(L) =:= length([I || I = {_, _} <- L]). |