Don't crash on malformed 'modules' section

This commit is contained in:
Evgeny Khramtsov 2019-02-19 12:31:18 +03:00
parent b30775a357
commit 8def827f9c
2 changed files with 16 additions and 6 deletions

View File

@ -713,10 +713,16 @@ process_term(Term, State) ->
process_host_term(Term, Host, State, Action) -> process_host_term(Term, Host, State, Action) ->
case Term of case Term of
{modules, Modules} when Action == set -> {modules, Modules} ->
set_option({modules, Host}, replace_modules(Modules), State); Modules1 = try (gen_mod:opt_type(modules))(Modules) of
{modules, Modules} when Action == append -> _ -> replace_modules(Modules)
append_option({modules, Host}, replace_modules(Modules), State); catch _:_ -> Modules
end,
if Action == set ->
set_option({modules, Host}, Modules1, State);
Action == append ->
append_option({modules, Host}, Modules1, State)
end;
{host, _} -> {host, _} ->
State; State;
{hosts, _} -> {hosts, _} ->

View File

@ -937,8 +937,12 @@ opt_type(modules) ->
fun(Mods) -> fun(Mods) ->
lists:map( lists:map(
fun({M, A}) when is_atom(M) -> fun({M, A}) when is_atom(M) ->
true = is_opt_list(A), case is_opt_list(A) of
{M, A} true -> {M, A};
false ->
?ERROR_MSG("Malformed configuration format of module ~s", [M]),
erlang:error(badarg)
end
end, Mods) end, Mods)
end; end;
opt_type(_) -> [modules]. opt_type(_) -> [modules].