File tree Expand file tree Collapse file tree 2 files changed +11
-0
lines changed Expand file tree Collapse file tree 2 files changed +11
-0
lines changed Original file line number Diff line number Diff line change @@ -334,6 +334,13 @@ impl FileDescription for FileHandle {
334
334
) -> InterpResult < ' tcx > {
335
335
assert ! ( communicate_allowed, "isolation should have prevented even opening a file" ) ;
336
336
337
+ if !self . writable {
338
+ // Linux returns EBADF here which we can't emulate via the platform-independent
339
+ // code since it does not map to any `io::ErrorKind`. So let's hard-code this.
340
+ if ecx. target_os_is_unix ( ) {
341
+ return finish. call ( ecx, Err ( IoError :: LibcError ( "EBADF" ) ) ) ;
342
+ }
343
+ }
337
344
let result = ecx. write_to_host ( & self . file , len, ptr) ?;
338
345
finish. call ( ecx, result)
339
346
}
Original file line number Diff line number Diff line change @@ -67,6 +67,10 @@ fn test_file() {
67
67
68
68
assert ! ( !file. is_terminal( ) ) ;
69
69
70
+ // Writing to a file opened for reading should error (and not stop interpretation). std does not
71
+ // categorize the error so we don't check for details.
72
+ file. write ( & [ ] ) . unwrap_err ( ) ;
73
+
70
74
// Removing file should succeed.
71
75
remove_file ( & path) . unwrap ( ) ;
72
76
}
You can’t perform that action at this time.
0 commit comments