crypto: Error on empty SSH_AUTH_SOCK

The empty string will never give a useful socket.

Co-authored-by: Lorenz Leutgeb <lorenz.leutgeb@radicle.dev>
This commit is contained in:
Steven Roose
2026-09-04 13:58:57 +02:00
committed by Lorenz Leutgeb
co-authored by Lorenz Leutgeb
parent 50129a7179
commit 919d5c780c
+6 -1
View File
@@ -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.