History

fix: Honor `disallow_shell` in SSH client feature check

When running an SSH client, the `disallow_shell` option determines whether the client command, before arguments, is to be run directly or if it is to be run by a shell. (One example of when it is run directly is if it comes from the `GIT_SSH` environment variable, while one example of when it is run by a shell is if it comes from the `GIT_SSH_COMMAND` environment variable.) When invoking the client in the most central and common case of actually attempting to connect to a remote server, `disallow_shell` was already followed. However, in some cases we are not sure what kind of SSH client program we have, and so to find that out (so we know how to run it to connect to a server), we run a test command, to see if it recognizes `-G` as OpenSSH clients do. Often we can tell what kind of client program we have without needing to do that. But if we do need to do it, we pre-run the client to check. In this use, the `disallow_shell` option was not followed, and instead the use of a shell was unconditionally treated as allowed. This fixes that by setting `prepare.use_shell = false` on a constructed `gix_command::Prepare` instance, which seems to be the prevailing style for achieving this elsewhere in `gix-transport`.

Eliah Kagan committed 1 year ago

Commit a445b721 parent 38a0d9a1 file · +8 −4Browse files

Unified · Split

gix-transport/src/client/blocking_io/ssh/mod.rs+8−4
@@ -111,8 +111,8 @@ pub fn connect( · 110 unmodified lines
111 let ssh_cmd = options.ssh_command();111 let ssh_cmd = options.ssh_command();
112 let mut kind = options.kind.unwrap_or_else(|| ProgramKind::from(ssh_cmd));112 let mut kind = options.kind.unwrap_or_else(|| ProgramKind::from(ssh_cmd));
113 if options.kind.is_none() && kind == ProgramKind::Simple {113 if options.kind.is_none() && kind == ProgramKind::Simple {
114 let mut cmd = std::process::Command::from(114 let mut cmd = std::process::Command::from({
115 gix_command::prepare(ssh_cmd)115 let mut prepare = gix_command::prepare(ssh_cmd)
116 .stderr(Stdio::null())116 .stderr(Stdio::null())
117 .stdout(Stdio::null())117 .stdout(Stdio::null())
118 .stdin(Stdio::null())118 .stdin(Stdio::null())
@@ -122,8 +122,12 @@ pub fn connect( · 3 unmodified lines
122 Usable(host) => host,122 Usable(host) => host,
123 Dangerous(host) => Err(Error::AmbiguousHostName { host: host.into() })?,123 Dangerous(host) => Err(Error::AmbiguousHostName { host: host.into() })?,
124 Absent => panic!("BUG: host should always be present in SSH URLs"),124 Absent => panic!("BUG: host should always be present in SSH URLs"),
125 }),125 });
126 );126 if options.disallow_shell {
127 prepare.use_shell = false;
128 }
129 prepare
130 });
127 gix_features::trace::debug!(cmd = ?cmd, "invoking `ssh` for feature check");131 gix_features::trace::debug!(cmd = ?cmd, "invoking `ssh` for feature check");
128 kind = if cmd.status().ok().is_some_and(|status| status.success()) {132 kind = if cmd.status().ok().is_some_and(|status| status.success()) {
129 ProgramKind::Ssh133 ProgramKind::Ssh

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t