Skip to content

Commit 07cf17f

Browse files
committed
pam: Insert newline when read fails
Fixes #1171 Signed-off-by: Wesley Hershberger <[email protected]>
1 parent 809e13e commit 07cf17f

File tree

1 file changed

+13
-2
lines changed

1 file changed

+13
-2
lines changed

src/pam/rpassword.rs

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -271,15 +271,20 @@ impl Terminal<'_> {
271271
pub fn read_password(&mut self, timeout: Option<Duration>) -> io::Result<PamBuffer> {
272272
let mut input = self.source_timeout(timeout);
273273
let _hide_input = HiddenInput::new(false)?;
274-
read_unbuffered(&mut input)
274+
let ret = read_unbuffered(&mut input);
275+
if ret.is_err() {
276+
let _ = self.sink().write(b"\n");
277+
}
278+
279+
ret
275280
}
276281

277282
/// Reads input with TTY echo disabled, but do provide visual feedback while typing.
278283
pub fn read_password_with_feedback(
279284
&mut self,
280285
timeout: Option<Duration>,
281286
) -> io::Result<PamBuffer> {
282-
if let Some(hide_input) = HiddenInput::new(true)? {
287+
let ret = if let Some(hide_input) = HiddenInput::new(true)? {
283288
match self {
284289
Terminal::StdIE(stdin, stdout) => {
285290
let mut reader = TimeoutRead::new(stdin.as_fd(), timeout);
@@ -292,7 +297,13 @@ impl Terminal<'_> {
292297
}
293298
} else {
294299
read_unbuffered(&mut self.source_timeout(timeout))
300+
};
301+
302+
if ret.is_err() {
303+
let _ = self.sink().write(b"\n");
295304
}
305+
306+
ret
296307
}
297308

298309
/// Reads input with TTY echo enabled

0 commit comments

Comments
 (0)