From 919d5c780c4da0b5b9f18f1549bc59dffd7125af Mon Sep 17 00:00:00 2001 From: Steven Roose Date: Tue, 28 Jul 2026 17:47:06 +0100 Subject: [PATCH] crypto: Error on empty `SSH_AUTH_SOCK` The empty string will never give a useful socket. Co-authored-by: Lorenz Leutgeb --- crates/radicle-crypto/src/ssh/agent.rs | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/crates/radicle-crypto/src/ssh/agent.rs b/crates/radicle-crypto/src/ssh/agent.rs index f48b27f13..f6610cb15 100644 --- a/crates/radicle-crypto/src/ssh/agent.rs +++ b/crates/radicle-crypto/src/ssh/agent.rs @@ -29,6 +29,8 @@ pub enum ConnectError { Agent(#[from] AgentError), #[error("Unable to read environment variable '{var}': {source}")] EnvVar { var: String, source: VarError }, + #[error("Environment variable '{var}' is set to the empty string.")] + EnvVarEmpty { var: String }, } impl ConnectError { @@ -72,7 +74,10 @@ impl Agent { const SSH_AUTH_SOCK: &str = "SSH_AUTH_SOCK"; let path = match std::env::var(SSH_AUTH_SOCK) { - Ok(path) => Ok(PathBuf::from(path)), + Ok(path) if !path.is_empty() => Ok(PathBuf::from(path)), + Ok(_) => Err(ConnectError::EnvVarEmpty { + var: SSH_AUTH_SOCK.to_string(), + }), #[cfg(windows)] Err(VarError::NotPresent) => { // Windows exposes the SSH Agent on a default named pipe.