From 1d8db94639a47f7b651be8cbfc814aa8ca4c91ee Mon Sep 17 00:00:00 2001 From: Tino Breddin Date: Wed, 21 Aug 2019 15:03:00 +0200 Subject: [PATCH] Ensure provider hook calls don't crash because of invalid command line arguments Normally the CLI arguments are intended for the provider which is called directly. When these are forwarded to other providers through hooks things might break. --- src/rebar_hooks.erl | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/src/rebar_hooks.erl b/src/rebar_hooks.erl index 358458edb..c0f3ca79b 100644 --- a/src/rebar_hooks.erl +++ b/src/rebar_hooks.erl @@ -22,9 +22,13 @@ run_all_hooks(Dir, Type, Command, Providers, State) -> run_hooks(Dir, Type, Command, rebar_state:opts(State), State). run_project_and_app_hooks(Dir, Type, Command, Providers, State) -> - ProjectApps = rebar_state:project_apps(State), - [rebar_hooks:run_all_hooks(Dir, Type, Command, Providers, AppInfo, State) || AppInfo <- ProjectApps], - run_all_hooks(Dir, Type, Command, Providers, State). + % The command_args which the original invocation of rebar received are most + % likely not applicable to the hooks which will be called. Therefore, the + % args are discarded to not crash provider hook invocations. + State1 = rebar_state:command_args(State, []), + ProjectApps = rebar_state:project_apps(State1), + [rebar_hooks:run_all_hooks(Dir, Type, Command, Providers, AppInfo, State1) || AppInfo <- ProjectApps], + run_all_hooks(Dir, Type, Command, Providers, State1). run_provider_hooks(Dir, Type, Command, Providers, Opts, State) -> case rebar_opts:get(Opts, provider_hooks, []) of