Skip to content

Commit bc482aa

Browse files
committed
Make sure paths are quoted when passing them to the shell that runs the signing command.
We run it in a shell, specifically the Git shell, on Windows so more programs are available. On Unix it sholdn't hurt even though it doesn't have a specific purpose there. The quoting is needed on Windows to prevent backslashes to mean escaping.
1 parent 8510243 commit bc482aa

File tree

1 file changed

+6
-4
lines changed

1 file changed

+6
-4
lines changed

crates/gitbutler-repo/src/repository_ext.rs

+6-4
Original file line numberDiff line numberDiff line change
@@ -450,13 +450,13 @@ impl RepositoryExt for git2::Repository {
450450
}
451451

452452
let args = format!(
453-
"{} -U {}",
453+
"'{}' -U '{}'",
454454
key_storage.path().to_string_lossy(),
455455
buffer_file_to_sign_path_str,
456456
);
457457
cmd_string += &args;
458458
} else {
459-
let args = format!("{} {}", signing_key, buffer_file_to_sign_path_str);
459+
let args = format!("'{}' '{}'", signing_key, buffer_file_to_sign_path_str);
460460
cmd_string += &args;
461461
};
462462
let mut signing_cmd: std::process::Command = command_with_login_shell(cmd_string);
@@ -581,11 +581,13 @@ impl RepositoryExt for git2::Repository {
581581
}
582582

583583
pub fn command_with_login_shell(shell_cmd: impl Into<OsString>) -> std::process::Command {
584-
gix::command::prepare(shell_cmd)
584+
let cmd: std::process::Command = gix::command::prepare(shell_cmd)
585585
.with_shell_disallow_manual_argument_splitting()
586586
// On Windows, this yields the Git-bundled `sh.exe`, on Linux it uses `/bin/sh`.
587587
.with_shell_program(gix::path::env::shell())
588-
.into()
588+
.into();
589+
tracing::debug!(?cmd, "command to produce commit signature");
590+
cmd
589591
}
590592

591593
/// Signs the buffer with the configured gpg key, returning the signature.

0 commit comments

Comments
 (0)