Skip to content

Commit

Permalink
sanitize password
Browse files Browse the repository at this point in the history
  • Loading branch information
UMR1352 committed Apr 30, 2024
1 parent cedf31a commit e6250db
Showing 1 changed file with 9 additions and 0 deletions.
9 changes: 9 additions & 0 deletions bindings/grpc/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ fn init_stronghold() -> anyhow::Result<StrongholdStorage> {
let stronghold_password = env::var("STRONGHOLD_PWD_FILE")
.context("Unset \"STRONGHOLD_PWD_FILE\" env variable")
.and_then(|path| fs::read_to_string(&path).context(format!("{path} does not exists")))
.map(sanitize_pwd)
.or(env::var("STRONGHOLD_PWD"))
.context("No password for stronghold was provided")?;
let snapshot_path = env::var("SNAPSHOT_PATH")?;
Expand All @@ -52,3 +53,11 @@ fn init_stronghold() -> anyhow::Result<StrongholdStorage> {
.map(StrongholdStorage::new)?,
)
}

/// Remove any trailing whitespace in-place.
fn sanitize_pwd(mut pwd: String) -> String {
let trimmed = pwd.trim_end();
pwd.truncate(trimmed.len());
pwd.shrink_to_fit();
pwd
}

0 comments on commit e6250db

Please sign in to comment.