File tree Expand file tree Collapse file tree 1 file changed +5
-2
lines changed Expand file tree Collapse file tree 1 file changed +5
-2
lines changed Original file line number Diff line number Diff line change @@ -67,7 +67,7 @@ pub fn terminal_size(out: &Term) -> Option<(u16, u16)> {
67
67
}
68
68
69
69
pub fn read_secure ( ) -> io:: Result < String > {
70
- let f_tty;
70
+ let mut f_tty;
71
71
let fd = unsafe {
72
72
if libc:: isatty ( libc:: STDIN_FILENO ) == 1 {
73
73
f_tty = None ;
@@ -91,14 +91,17 @@ pub fn read_secure() -> io::Result<String> {
91
91
c_result ( || unsafe { libc:: tcsetattr ( fd, libc:: TCSAFLUSH , & termios) } ) ?;
92
92
let mut rv = String :: new ( ) ;
93
93
94
- let read_rv = if let Some ( mut f) = f_tty {
94
+ let read_rv = if let Some ( f) = & mut f_tty {
95
95
f. read_line ( & mut rv)
96
96
} else {
97
97
io:: stdin ( ) . read_line ( & mut rv)
98
98
} ;
99
99
100
100
c_result ( || unsafe { libc:: tcsetattr ( fd, libc:: TCSAFLUSH , & original) } ) ?;
101
101
102
+ // Ensure the fd is only closed after everything has been restored.
103
+ drop ( f_tty) ;
104
+
102
105
read_rv. map ( |_| {
103
106
let len = rv. trim_end_matches ( & [ '\r' , '\n' ] [ ..] ) . len ( ) ;
104
107
rv. truncate ( len) ;
You can’t perform that action at this time.
0 commit comments