Skip to content

armgit / kanzo

Public Imported from GitHub
0

Self-hosted, sharable kanban for humans and agents. One 4.7 MB binary, 5 MB of RAM, 10 to 60 tokens per agent reply, starts in 3 ms, zero setup.

Refuse repo URLs that git would read as options

emanuele-emffd153d14db0
diff --git a/src/sync.rs b/src/sync.rs
index 11376b9..da1a884 100644
--- a/src/sync.rs
+++ b/src/sync.rs
@@ -43,10 +43,14 @@ pub fn set_remote(home: &Home, url: &str, prompt: bool) -> Result<String> {
if url.is_empty() {
bail!("Paste the URL of a git repository, like https://github.com/you/kanzo-data");
}
+ // Git would read it as an option, like --upload-pack, which runs a command.
+ if url.starts_with('-') {
+ bail!("That's not a repo URL: it starts with '-'.");
+ }
let mut failure = String::new();
let mut found = None;
for candidate in candidates(url) {
- match git(dir, prompt, &["ls-remote", "--symref", &candidate, "HEAD"]) {
+ match git(dir, prompt, &["ls-remote", "--symref", "--", &candidate, "HEAD"]) {
Ok(out) => {
found = Some((candidate, out));
break;
@@ -69,7 +73,7 @@ pub fn set_remote(home: &Home, url: &str, prompt: bool) -> Result<String> {
if let Some((old, _)) = current {
git(dir, prompt, &["remote", "remove", &old])?;
}
- git(dir, prompt, &["remote", "add", "origin", &url])?;
+ git(dir, prompt, &["remote", "add", "--", "origin", &url])?;
}
Ok(url)
}
@@ -291,6 +295,15 @@ fn hostname() -> String {
mod tests {
use super::*;
+ #[test]
+ fn refuses_options_as_urls() {
+ let tmp = tempfile::tempdir().unwrap();
+ let home = Home::open(tmp.path().to_path_buf()).unwrap();
+ let err = set_remote(&home, "--upload-pack=touch pwned;", false).unwrap_err();
+ assert!(err.to_string().contains("starts with '-'"));
+ assert!(!tmp.path().join("pwned").exists());
+ }
+
#[test]
fn urls() {
let ssh = "[email protected]:you/kanzo-data.git";