From: Evgeniy Khramtsov Date: Mon, 16 Apr 2018 12:48:06 +0000 (+0300) Subject: Carefully validate options list X-Git-Tag: 18.04~26 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=acc162f4f44e19a84a0c8f1d747dd9dc1a500ec3;p=ejabberd Carefully validate options list --- diff --git a/src/gen_mod.erl b/src/gen_mod.erl index 0b7820fc6..1e069be73 100644 --- a/src/gen_mod.erl +++ b/src/gen_mod.erl @@ -654,11 +654,10 @@ merge_opts(Opts, DefaultOpts, Module) -> {_, Val} -> case Default of [{A, _}|_] when is_atom(A) andalso is_list(Val) -> - VFun = opt_type(modules), - try VFun(Val) of - NewVal -> - [{Opt, merge_opts(NewVal, Default, Module)}|Acc] - catch _:_ -> + case is_opt_list(Val) of + true -> + [{Opt, merge_opts(Val, Default, Module)}|Acc]; + false -> ?ERROR_MSG( "Ignoring invalid value '~p' for " "option '~s' of module '~s'", @@ -883,12 +882,24 @@ is_equal_opt(Opt, NewOpts, OldOpts) -> true 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()}]); (atom()) -> [atom()]. opt_type(modules) -> fun(Mods) -> 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} end, Mods) end;