From df9cf61575dcdfc0a160929bd8d85210d61464cb Mon Sep 17 00:00:00 2001 From: weishu Date: Fri, 28 Jul 2023 22:20:58 +0800 Subject: [PATCH] ksud: fix su args parse error. close #736 --- userspace/ksud/Cargo.toml | 2 +- userspace/ksud/src/ksu.rs | 22 +++++++--------------- 2 files changed, 8 insertions(+), 16 deletions(-) diff --git a/userspace/ksud/Cargo.toml b/userspace/ksud/Cargo.toml index 9c5dff68..fc9320ca 100644 --- a/userspace/ksud/Cargo.toml +++ b/userspace/ksud/Cargo.toml @@ -46,4 +46,4 @@ android_logger = "0.13" [profile.release] strip = true opt-level = "z" -lto = true +# lto = true diff --git a/userspace/ksud/src/ksu.rs b/userspace/ksud/src/ksu.rs index e386f5ba..6045a611 100644 --- a/userspace/ksud/src/ksu.rs +++ b/userspace/ksud/src/ksu.rs @@ -161,22 +161,14 @@ pub fn root_shell() -> Result<()> { let preserve_env = matches.opt_present("p"); let mount_master = matches.opt_present("M"); + // we've make sure that -c is the last option and it already contains the whole command, no need to construct it again + let args = matches + .opt_str("c") + .map(|cmd| vec!["-c".to_string(), cmd]) + .unwrap_or_default(); + let mut free_idx = 0; - let command = matches.opt_str("c").map(|cmd| { - free_idx = matches.free.len(); - let mut cmds = vec![]; - cmds.push(cmd); - cmds.extend(matches.free.clone()); - cmds - }); - - let mut args = vec![]; - if let Some(cmd) = command { - args.push("-c".to_string()); - args.push(cmd.join(" ")); - }; - - if free_idx < matches.free.len() && matches.free[free_idx] == "-" { + if !matches.free.is_empty() && matches.free[free_idx] == "-" { is_login = true; free_idx += 1; }