25
1
mirror of https://github.com/processone/ejabberd.git synced 2024-12-20 17:27:00 +01:00

Carefully validate options list

This commit is contained in:
Evgeniy Khramtsov 2018-04-16 15:48:06 +03:00
parent b8505f3e78
commit acc162f4f4

View File

@ -654,11 +654,10 @@ merge_opts(Opts, DefaultOpts, Module) ->
{_, Val} -> {_, Val} ->
case Default of case Default of
[{A, _}|_] when is_atom(A) andalso is_list(Val) -> [{A, _}|_] when is_atom(A) andalso is_list(Val) ->
VFun = opt_type(modules), case is_opt_list(Val) of
try VFun(Val) of true ->
NewVal -> [{Opt, merge_opts(Val, Default, Module)}|Acc];
[{Opt, merge_opts(NewVal, Default, Module)}|Acc] false ->
catch _:_ ->
?ERROR_MSG( ?ERROR_MSG(
"Ignoring invalid value '~p' for " "Ignoring invalid value '~p' for "
"option '~s' of module '~s'", "option '~s' of module '~s'",
@ -883,12 +882,24 @@ is_equal_opt(Opt, NewOpts, OldOpts) ->
true true
end. end.
-spec is_opt_list(term()) -> boolean().
is_opt_list([]) ->
true;
is_opt_list(L) when is_list(L) ->
lists:all(
fun({Opt, _Val}) -> is_atom(Opt);
(_) -> false
end, L);
is_opt_list(_) ->
false.
-spec opt_type(modules) -> fun(([{atom(), list()}]) -> [{atom(), list()}]); -spec opt_type(modules) -> fun(([{atom(), list()}]) -> [{atom(), list()}]);
(atom()) -> [atom()]. (atom()) -> [atom()].
opt_type(modules) -> opt_type(modules) ->
fun(Mods) -> fun(Mods) ->
lists:map( lists:map(
fun({M, A}) when is_atom(M), is_list(A) -> fun({M, A}) when is_atom(M) ->
true = is_opt_list(A),
{M, A} {M, A}
end, Mods) end, Mods)
end; end;