Ensure the buffer used in `prompt` is zeroized even on error.
Co-authored-by: Jack Grigg <str4d@electriccoin.co> Signed-off-by: Daira Hopwood <daira@jacaranda.org>
This commit is contained in:
parent
7a98644ff2
commit
d5b6e226f0
|
@ -496,12 +496,16 @@ fn prompt(input: &mut Stdin) -> anyhow::Result<SecretString> {
|
|||
let res = input
|
||||
.read_line(&mut buf)
|
||||
.with_context(|| "Error reading from stdin");
|
||||
if !buf.ends_with('\n') {
|
||||
return Err(WalletToolError::UnexpectedEof.into());
|
||||
}
|
||||
// TODO: Ensure the buffer is zeroized even on error.
|
||||
|
||||
// Ensure the buffer is zeroized even on error.
|
||||
let line = SecretString::new(buf);
|
||||
res.map(|_| line)
|
||||
res.and_then(|_| {
|
||||
if line.expose_secret().ends_with('\n') {
|
||||
Ok(line)
|
||||
} else {
|
||||
Err(WalletToolError::UnexpectedEof.into())
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
fn strip(input: &SecretString) -> &str {
|
||||
|
|
Loading…
Reference in New Issue