25
1
mirror of https://github.com/processone/ejabberd.git synced 2024-11-22 16:20:52 +01:00

Don't crash on invalid module's sub-options

Fixes #2387
This commit is contained in:
Evgeniy Khramtsov 2018-04-16 11:06:57 +03:00
parent 8a71e2e4f7
commit b8505f3e78

View File

@ -548,7 +548,7 @@ validate_opts(Host, Module, Opts0) ->
end, [Module|SubMods]),
Required = lists:filter(fun is_atom/1, DefaultOpts),
try
Opts = merge_opts(Opts0, DefaultOpts),
Opts = merge_opts(Opts0, DefaultOpts, Module),
{ok, case get_validators(Host, {Module, SubMods}) of
undef ->
Opts;
@ -645,8 +645,8 @@ list_known_opts(Host, Module) ->
Module:mod_opt_type('')
end.
-spec merge_opts(opts(), opts()) -> opts().
merge_opts(Opts, DefaultOpts) ->
-spec merge_opts(opts(), opts(), module()) -> opts().
merge_opts(Opts, DefaultOpts, Module) ->
Result =
lists:foldr(
fun({Opt, Default}, Acc) ->
@ -654,7 +654,17 @@ merge_opts(Opts, DefaultOpts) ->
{_, Val} ->
case Default of
[{A, _}|_] when is_atom(A) andalso is_list(Val) ->
[{Opt, merge_opts(Val, Default)}|Acc];
VFun = opt_type(modules),
try VFun(Val) of
NewVal ->
[{Opt, merge_opts(NewVal, Default, Module)}|Acc]
catch _:_ ->
?ERROR_MSG(
"Ignoring invalid value '~p' for "
"option '~s' of module '~s'",
[Val, Opt, Module]),
[{Opt, Default}|Acc]
end;
Val ->
[{Opt, Default}|Acc];
_ ->