Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions src/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,17 @@ pub fn run_bitcoin_cli(
profile: &Profile,
args: &[String],
) -> Result<String, crate::error::AppError> {
let file_name = std::path::Path::new(&profile.bitcoin_cli)
.file_name()
.and_then(|n| n.to_str())
.unwrap_or("");

if file_name != "bitcoin-cli" && file_name != "bitcoin-cli.exe" {
return Err(crate::error::AppError::Config(
"Invalid bitcoin-cli binary. Only 'bitcoin-cli' or 'bitcoin-cli.exe' are allowed for security reasons.".to_string(),
));
}

let mut cmd = std::process::Command::new(&profile.bitcoin_cli);
for arg in &profile.bitcoin_cli_args {
cmd.arg(arg);
Expand Down
22 changes: 0 additions & 22 deletions src/wallet_service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ use rpassword::read_password;
use std::fs;
use std::io::{self, Write};
use std::path::{Path, PathBuf};
use std::process::Command as ShellCommand;

pub use zinc_core::{
decrypt_wallet_internal, encrypt_wallet_internal, generate_wallet_internal,
Expand Down Expand Up @@ -226,27 +225,6 @@ pub fn persist_wallet_session(session: &mut WalletSession) -> Result<(), AppErro
write_profile(&session.profile_path, &session.profile)
}

#[allow(dead_code)]
pub fn run_bitcoin_cli(profile: &Profile, args: &[String]) -> Result<String, AppError> {
let output = ShellCommand::new(&profile.bitcoin_cli)
.args(&profile.bitcoin_cli_args)
.args(args)
.output()
.map_err(|e| AppError::Config(format!("failed to launch {}: {e}", profile.bitcoin_cli)))?;

if !output.status.success() {
let stderr = String::from_utf8_lossy(&output.stderr).trim().to_string();
let stdout = String::from_utf8_lossy(&output.stdout).trim().to_string();
let details = if !stderr.is_empty() { stderr } else { stdout };
return Err(AppError::Network(format!(
"bitcoin-cli command failed: {} {}",
profile.bitcoin_cli, details
)));
}

Ok(String::from_utf8_lossy(&output.stdout).trim().to_string())
}

#[cfg(test)]
mod tests {
use super::*;
Expand Down
Loading