Skip to content

Commit

Permalink
wasi-common: normalize wrong access mode error on windows to badf
Browse files Browse the repository at this point in the history
  • Loading branch information
Pat Hickey committed May 26, 2023
1 parent d808cce commit 0d8a260
Showing 1 changed file with 16 additions and 0 deletions.
16 changes: 16 additions & 0 deletions crates/wasi-common/src/snapshots/preview_1.rs
Original file line number Diff line number Diff line change
Expand Up @@ -293,6 +293,10 @@ impl wasi_snapshot_preview1::WasiSnapshotPreview1 for WasiCtx {
iovs: &types::IovecArray<'a>,
) -> Result<types::Size, Error> {
let f = self.table().get_file(u32::from(fd))?;
// Access mode check normalizes error returned (windows would prefer ACCES here)
if !f.access_mode.contains(FileAccessMode::READ) {
Err(types::Errno::Badf)?
}
let f = &f.file;

let iovs: Vec<wiggle::GuestPtr<[u8]>> = iovs
Expand Down Expand Up @@ -364,6 +368,10 @@ impl wasi_snapshot_preview1::WasiSnapshotPreview1 for WasiCtx {
offset: types::Filesize,
) -> Result<types::Size, Error> {
let f = self.table().get_file(u32::from(fd))?;
// Access mode check normalizes error returned (windows would prefer ACCES here)
if !f.access_mode.contains(FileAccessMode::READ) {
Err(types::Errno::Badf)?
}
let f = &f.file;

let iovs: Vec<wiggle::GuestPtr<[u8]>> = iovs
Expand Down Expand Up @@ -436,6 +444,10 @@ impl wasi_snapshot_preview1::WasiSnapshotPreview1 for WasiCtx {
ciovs: &types::CiovecArray<'a>,
) -> Result<types::Size, Error> {
let f = self.table().get_file(u32::from(fd))?;
// Access mode check normalizes error returned (windows would prefer ACCES here)
if !f.access_mode.contains(FileAccessMode::WRITE) {
Err(types::Errno::Badf)?
}
let f = &f.file;

let guest_slices: Vec<wiggle::GuestCow<u8>> = ciovs
Expand Down Expand Up @@ -463,6 +475,10 @@ impl wasi_snapshot_preview1::WasiSnapshotPreview1 for WasiCtx {
offset: types::Filesize,
) -> Result<types::Size, Error> {
let f = self.table().get_file(u32::from(fd))?;
// Access mode check normalizes error returned (windows would prefer ACCES here)
if !f.access_mode.contains(FileAccessMode::WRITE) {
Err(types::Errno::Badf)?
}
let f = &f.file;

let guest_slices: Vec<wiggle::GuestCow<u8>> = ciovs
Expand Down

0 comments on commit 0d8a260

Please sign in to comment.