Skip to content

Commit

Permalink
Fix WasiCtxBuilder so that stdin, stdout, and stderr accept files.
Browse files Browse the repository at this point in the history
A regression in bytecodealliance#1561 caused "invalid argument" errors when `stdin`, `stdout`,
and `stderr` are given a file handle.

This was missed in Wasmtime CI because previously only a pipe handle was being
used.

It was caught in the .NET implementation CI because it uses file handles for
its WASI tests.

Fixes bytecodealliance#1735.
  • Loading branch information
peterhuene committed May 21, 2020
1 parent c9e3b71 commit 21b0d6e
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions crates/wasi-common/src/ctx.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ use crate::entry::{Entry, EntryHandle};
use crate::fdpool::FdPool;
use crate::handle::Handle;
use crate::sys::osdir::OsDir;
use crate::sys::osfile::OsFile;
use crate::sys::osother::{OsOther, OsOtherExt};
use crate::sys::stdio::{Stderr, StderrExt, Stdin, StdinExt, Stdout, StdoutExt};
use crate::virtfs::{VirtualDir, VirtualDirEntry};
Expand Down Expand Up @@ -369,8 +370,11 @@ impl WasiCtxBuilder {
.ok_or(WasiCtxBuilderError::TooManyFilesOpen)?
}
PendingEntry::OsHandle(f) => {
let handle = OsOther::try_from(f)?;
let handle = EntryHandle::new(handle);
let handle = if f.metadata()?.is_file() {
EntryHandle::new(OsFile::try_from(f)?)
} else {
EntryHandle::new(OsOther::try_from(f)?)
};
let entry = Entry::new(handle);
entries
.insert(entry)
Expand All @@ -379,6 +383,7 @@ impl WasiCtxBuilder {
};
log::debug!("WasiCtx inserted at {:?}", fd);
}

// Then add the preopen entries.
for (guest_path, preopen) in self.preopens.take().unwrap() {
let handle = EntryHandle::from(preopen.into()?);
Expand Down

0 comments on commit 21b0d6e

Please sign in to comment.