@@ -63,7 +63,7 @@ pub trait FileDescriptor: std::fmt::Debug + Any {
63
63
64
64
fn dup ( & mut self ) -> io:: Result < Box < dyn FileDescriptor > > ;
65
65
66
- fn is_tty ( & self ) -> bool {
66
+ fn is_tty ( & self , _communicate_allowed : bool ) -> bool {
67
67
false
68
68
}
69
69
@@ -156,8 +156,8 @@ impl FileDescriptor for FileHandle {
156
156
Some ( self . file . as_raw_fd ( ) )
157
157
}
158
158
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 ( )
161
161
}
162
162
}
163
163
@@ -188,8 +188,8 @@ impl FileDescriptor for io::Stdin {
188
188
Some ( libc:: STDIN_FILENO )
189
189
}
190
190
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 ( )
193
193
}
194
194
}
195
195
@@ -225,8 +225,8 @@ impl FileDescriptor for io::Stdout {
225
225
Some ( libc:: STDOUT_FILENO )
226
226
}
227
227
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 ( )
230
230
}
231
231
}
232
232
@@ -255,8 +255,8 @@ impl FileDescriptor for io::Stderr {
255
255
Some ( libc:: STDERR_FILENO )
256
256
}
257
257
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 ( )
260
260
}
261
261
}
262
262
@@ -1721,15 +1721,18 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriInterpCxExt<'mir, 'tcx> {
1721
1721
let this = self . eval_context_mut ( ) ;
1722
1722
// "returns 1 if fd is an open file descriptor referring to a terminal;
1723
1723
// 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 ( ) ) {
1727
1727
return Ok ( Scalar :: from_i32 ( 1 ) ) ;
1728
+ } else {
1729
+ this. eval_libc ( "ENOTTY" )
1728
1730
}
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) ?;
1733
1736
Ok ( Scalar :: from_i32 ( 0 ) )
1734
1737
}
1735
1738
0 commit comments