From 7d28f121c7baba31f5bd731de8aff023fa23bdc0 Mon Sep 17 00:00:00 2001 From: Profpatsch Date: Sat, 6 Feb 2021 22:23:32 +0100 Subject: fix(users/Profpatsch/execline): fix exec_into_args off-by-1 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit We expect the users to pass an actual prog, not an argv, so 0 is the program to exec into. Also improve the exec error, by including the program we tried to exec into (the rust IO error doesn’t contain the name). Change-Id: I664f9f717e4f82bfc1b1da3bd7114124b7582d5f Reviewed-on: https://cl.tvl.fyi/c/depot/+/2489 Reviewed-by: Profpatsch Tested-by: BuildkiteCI --- users/Profpatsch/execline/exec_helpers.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/users/Profpatsch/execline/exec_helpers.rs b/users/Profpatsch/execline/exec_helpers.rs index 3e74ffc72210..9a67ffe45db5 100644 --- a/users/Profpatsch/execline/exec_helpers.rs +++ b/users/Profpatsch/execline/exec_helpers.rs @@ -31,12 +31,12 @@ pub fn exec_into_args<'a, 'b, Args, Arg, Env, Key, Val>(current_prog_name: &str, // TODO: is this possible without collecting into a Vec first, just leaving it an IntoIterator? let args = args.into_iter().collect::>(); let mut args = args.iter().map(|v| OsStr::from_bytes(v.as_ref())); - let prog = args.nth(1).expect(&format!("{}: first argument must be an executable", current_prog_name)); + let prog = args.nth(0).expect(&format!("{}: first argument must be an executable", current_prog_name)); // TODO: same here let env = env_additions.into_iter().collect::>(); let env = env.iter().map(|(k,v)| (OsStr::from_bytes(k.as_ref()), OsStr::from_bytes(v.as_ref()))); let err = std::process::Command::new(prog).args(args).envs(env).exec(); - die_missing_executable(current_prog_name, format!("exec failed: {:?}", err)); + die_missing_executable(current_prog_name, format!("exec failed: {}, while trying to execing into {:?}", err, prog)); } /// Exit 1 to signify a generic expected error -- cgit 1.4.1