`fd_advise` on invalid file descriptors report ok
Closed this issue · 0 comments
yagehu commented
Describe the bug
Calling fd_advise
on a clearly invalid file descriptor returns 0 in all conditions.
Minimal Rust repro:
use wasi::ADVICE_WILLNEED;
fn main() {
unsafe {
let result = wasi::fd_advise(6, 0, 0, ADVICE_WILLNEED);
match result {
Ok(()) => eprintln!("fd_advise ok"),
Err(errno) => eprintln!("fd_advise failed with {errno}"),
}
}
}
$ cargo build --target wasm32-wasi
$ wasmer -vV; rustc -vV
wasmer 4.2.5 (0460050 2024-03-05)
binary: wasmer-cli
commit-hash: 04600507844bae978239531c8e6265d410aefe6d
commit-date: 2024-03-05
host: x86_64-unknown-linux-gnu
compiler: singlepass,cranelift
rustc 1.77.1 (7cf61ebde 2024-03-27)
binary: rustc
commit-hash: 7cf61ebde7b22796c69757901dd346d0fe70bd97
commit-date: 2024-03-27
host: x86_64-unknown-linux-gnu
release: 1.77.1
LLVM version: 17.0.6
Steps to reproduce
Run the above Rust snippet compiled to wasm32-wasi
. It should output fd_advise failed with <errno>
, but it reports fd_advise ok
.
Expected behavior
When the fd is invalid, like a random or very large number, fd_advise
should report something like ebadf
.
Actual behavior
fd_advise
returns ok (0) in all cases.
Additional context
This was uncovered in differential fuzzing between Wasmer and other Wasm/WASI runtimes. I have a simple PR to fix this behavior.