mirror of
https://github.com/openai/codex.git
synced 2026-04-24 14:45:27 +00:00
fix: protect dash against login
This commit is contained in:
@@ -37,7 +37,7 @@ impl Shell {
|
||||
/// use with `exec()` to run the shell command.
|
||||
pub fn derive_exec_args(&self, command: &str, use_login_shell: bool) -> Vec<String> {
|
||||
match self.shell_type {
|
||||
ShellType::Zsh | ShellType::Bash | ShellType::Sh => {
|
||||
ShellType::Zsh | ShellType::Bash => {
|
||||
let arg = if use_login_shell { "-lc" } else { "-c" };
|
||||
vec![
|
||||
self.shell_path.to_string_lossy().to_string(),
|
||||
@@ -45,6 +45,14 @@ impl Shell {
|
||||
command.to_string(),
|
||||
]
|
||||
}
|
||||
ShellType::Sh => {
|
||||
// POSIX sh (e.g., dash) doesn't accept -l, so always use -c.
|
||||
vec![
|
||||
self.shell_path.to_string_lossy().to_string(),
|
||||
"-c".to_string(),
|
||||
command.to_string(),
|
||||
]
|
||||
}
|
||||
ShellType::PowerShell => {
|
||||
let mut args = vec![self.shell_path.to_string_lossy().to_string()];
|
||||
if !use_login_shell {
|
||||
@@ -450,6 +458,20 @@ mod tests {
|
||||
vec!["/bin/zsh", "-lc", "echo hello"]
|
||||
);
|
||||
|
||||
let test_sh_shell = Shell {
|
||||
shell_type: ShellType::Sh,
|
||||
shell_path: PathBuf::from("/bin/sh"),
|
||||
shell_snapshot: None,
|
||||
};
|
||||
assert_eq!(
|
||||
test_sh_shell.derive_exec_args("echo hello", false),
|
||||
vec!["/bin/sh", "-c", "echo hello"]
|
||||
);
|
||||
assert_eq!(
|
||||
test_sh_shell.derive_exec_args("echo hello", true),
|
||||
vec!["/bin/sh", "-c", "echo hello"]
|
||||
);
|
||||
|
||||
let test_powershell_shell = Shell {
|
||||
shell_type: ShellType::PowerShell,
|
||||
shell_path: PathBuf::from("pwsh.exe"),
|
||||
|
||||
Reference in New Issue
Block a user