From 8def827f9cc1242e15af760bdd8419ddd167e3a6 Mon Sep 17 00:00:00 2001 From: Evgeny Khramtsov Date: Tue, 19 Feb 2019 12:31:18 +0300 Subject: Don't crash on malformed 'modules' section --- src/ejabberd_config.erl | 14 ++++++++++---- src/gen_mod.erl | 8 ++++++-- 2 files changed, 16 insertions(+), 6 deletions(-) diff --git a/src/ejabberd_config.erl b/src/ejabberd_config.erl index eaf513e77..ed52c728b 100644 --- a/src/ejabberd_config.erl +++ b/src/ejabberd_config.erl @@ -713,10 +713,16 @@ process_term(Term, State) -> process_host_term(Term, Host, State, Action) -> case Term of - {modules, Modules} when Action == set -> - set_option({modules, Host}, replace_modules(Modules), State); - {modules, Modules} when Action == append -> - append_option({modules, Host}, replace_modules(Modules), State); + {modules, Modules} -> + Modules1 = try (gen_mod:opt_type(modules))(Modules) of + _ -> replace_modules(Modules) + catch _:_ -> Modules + end, + if Action == set -> + set_option({modules, Host}, Modules1, State); + Action == append -> + append_option({modules, Host}, Modules1, State) + end; {host, _} -> State; {hosts, _} -> diff --git a/src/gen_mod.erl b/src/gen_mod.erl index 4d815073c..cec3ddb24 100644 --- a/src/gen_mod.erl +++ b/src/gen_mod.erl @@ -937,8 +937,12 @@ opt_type(modules) -> fun(Mods) -> lists:map( fun({M, A}) when is_atom(M) -> - true = is_opt_list(A), - {M, A} + case is_opt_list(A) of + true -> {M, A}; + false -> + ?ERROR_MSG("Malformed configuration format of module ~s", [M]), + erlang:error(badarg) + end end, Mods) end; opt_type(_) -> [modules]. -- cgit v1.2.3