Skip to content

Commit 3e5e247

Browse files
committed
Fix shell escaping in getting current env
Credit to Dario Weißer for bringing this to our attention.
1 parent 7e27171 commit 3e5e247

File tree

1 file changed

+9
-4
lines changed

1 file changed

+9
-4
lines changed

crates/util/src/shell_env.rs

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -94,8 +94,13 @@ async fn capture_unix(
9494
_ => command.args(["-i", "-c"]),
9595
};
9696

97+
let dir_str = directory.to_string_lossy();
98+
let safe_dir = shell_kind
99+
.try_quote(&dir_str)
100+
.context("unexpected null in directory name")?;
101+
97102
// cd into the directory, triggering directory specific side-effects (asdf, direnv, etc)
98-
command_string.push_str(&format!("cd '{}';", directory.display()));
103+
command_string.push_str(&format!("cd {};", safe_dir));
99104
if let Some(prefix) = shell_kind.command_prefix() {
100105
command_string.push(prefix);
101106
}
@@ -172,7 +177,7 @@ async fn capture_windows(
172177
shell_kind
173178
.try_quote(value)
174179
.map(|quoted| quoted.into_owned())
175-
.unwrap_or_else(|| value.to_owned())
180+
.context("unexpected null in directory name")
176181
};
177182
let mut cmd = crate::command::new_command(shell_path);
178183
cmd.args(args);
@@ -183,8 +188,8 @@ async fn capture_windows(
183188
| ShellKind::Fish
184189
| ShellKind::Xonsh
185190
| ShellKind::Posix => {
186-
let quoted_directory = quote_for_shell(&directory_string);
187-
let quoted_zed_path = quote_for_shell(&zed_path_string);
191+
let quoted_directory = quote_for_shell(&directory_string)?;
192+
let quoted_zed_path = quote_for_shell(&zed_path_string)?;
188193
cmd.args([
189194
"-l",
190195
"-i",

0 commit comments

Comments
 (0)