@@ -63,7 +63,7 @@ pub trait FileDescriptor: std::fmt::Debug + Any {
6363
6464 fn dup ( & mut self ) -> io:: Result < Box < dyn FileDescriptor > > ;
6565
66- fn is_tty ( & self ) -> bool {
66+ fn is_tty ( & self , _communicate_allowed : bool ) -> bool {
6767 false
6868 }
6969
@@ -156,8 +156,8 @@ impl FileDescriptor for FileHandle {
156156 Some ( self . file . as_raw_fd ( ) )
157157 }
158158
159- fn is_tty ( & self ) -> bool {
160- self . file . is_terminal ( )
159+ fn is_tty ( & self , communicate_allowed : bool ) -> bool {
160+ communicate_allowed && self . file . is_terminal ( )
161161 }
162162}
163163
@@ -188,8 +188,8 @@ impl FileDescriptor for io::Stdin {
188188 Some ( libc:: STDIN_FILENO )
189189 }
190190
191- fn is_tty ( & self ) -> bool {
192- self . is_terminal ( )
191+ fn is_tty ( & self , communicate_allowed : bool ) -> bool {
192+ communicate_allowed && self . is_terminal ( )
193193 }
194194}
195195
@@ -225,8 +225,8 @@ impl FileDescriptor for io::Stdout {
225225 Some ( libc:: STDOUT_FILENO )
226226 }
227227
228- fn is_tty ( & self ) -> bool {
229- self . is_terminal ( )
228+ fn is_tty ( & self , communicate_allowed : bool ) -> bool {
229+ communicate_allowed && self . is_terminal ( )
230230 }
231231}
232232
@@ -255,8 +255,8 @@ impl FileDescriptor for io::Stderr {
255255 Some ( libc:: STDERR_FILENO )
256256 }
257257
258- fn is_tty ( & self ) -> bool {
259- self . is_terminal ( )
258+ fn is_tty ( & self , communicate_allowed : bool ) -> bool {
259+ communicate_allowed && self . is_terminal ( )
260260 }
261261}
262262
@@ -1721,15 +1721,18 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriInterpCxExt<'mir, 'tcx> {
17211721 let this = self . eval_context_mut ( ) ;
17221722 // "returns 1 if fd is an open file descriptor referring to a terminal;
17231723 // otherwise 0 is returned, and errno is set to indicate the error"
1724- if matches ! ( this. machine . isolated_op , IsolatedOp :: Allow ) {
1725- let fd = this. read_scalar ( miri_fd ) ? . to_i32 ( ) ? ;
1726- if this. machine . file_handler . handles . get ( & fd ) . map ( |fd| fd . is_tty ( ) ) == Some ( true ) {
1724+ let fd = this. read_scalar ( miri_fd ) ? . to_i32 ( ) ? ;
1725+ let error = if let Some ( fd ) = this. machine . file_handler . handles . get ( & fd ) {
1726+ if fd . is_tty ( this. machine . communicate ( ) ) {
17271727 return Ok ( Scalar :: from_i32 ( 1 ) ) ;
1728+ } else {
1729+ this. eval_libc ( "ENOTTY" )
17281730 }
1729- }
1730- // Fallback when the FD was not found or isolation is enabled.
1731- let enotty = this. eval_libc ( "ENOTTY" ) ;
1732- this. set_last_error ( enotty) ?;
1731+ } else {
1732+ // FD does not exist
1733+ this. eval_libc ( "EBADF" )
1734+ } ;
1735+ this. set_last_error ( error) ?;
17331736 Ok ( Scalar :: from_i32 ( 0 ) )
17341737 }
17351738
0 commit comments