From e6250db4915cf45ef30acf7dbb2c6d02a57b8a92 Mon Sep 17 00:00:00 2001 From: Enrico Marconi Date: Tue, 30 Apr 2024 16:04:00 +0200 Subject: [PATCH] sanitize password --- bindings/grpc/src/main.rs | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/bindings/grpc/src/main.rs b/bindings/grpc/src/main.rs index dbc8cfb515..04927b1c9c 100644 --- a/bindings/grpc/src/main.rs +++ b/bindings/grpc/src/main.rs @@ -35,6 +35,7 @@ fn init_stronghold() -> anyhow::Result { 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")?; @@ -52,3 +53,11 @@ fn init_stronghold() -> anyhow::Result { .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 +}