From b572a32c1c2de0239e9cee306deac9ef186ebb09 Mon Sep 17 00:00:00 2001 From: Marcin Mielniczuk Date: Fri, 17 Jan 2020 19:48:26 +0100 Subject: [PATCH] Return EINVAL in poll_oneoff with no events. We adhere to WebAssembly/WASI#193. --- crates/wasi-common/src/hostcalls_impl/misc.rs | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/crates/wasi-common/src/hostcalls_impl/misc.rs b/crates/wasi-common/src/hostcalls_impl/misc.rs index 893d3dae0b73..f07aa727f4da 100644 --- a/crates/wasi-common/src/hostcalls_impl/misc.rs +++ b/crates/wasi-common/src/hostcalls_impl/misc.rs @@ -218,6 +218,12 @@ pub(crate) fn poll_oneoff( let mut timeout: Option = None; let mut fd_events = Vec::new(); + + // As mandated by the WASI spec: + // > If `nsubscriptions` is 0, returns `errno::inval`. + if subscriptions.is_empty() { + return Err(Error::EINVAL); + } for subscription in subscriptions { match subscription.r#type { wasi::__WASI_EVENTTYPE_CLOCK => { @@ -280,6 +286,9 @@ pub(crate) fn poll_oneoff( log::debug!("poll_oneoff timeout = {:?}", timeout); log::debug!("poll_oneoff fd_events = {:?}", fd_events); + // The underlying implementation should successfully and immediately return + // if no events have been passed. Such situation may occur if all provided + // events have been filtered out as errors in the code above. hostcalls_impl::poll_oneoff(timeout, fd_events, &mut events)?; let events_count = u32::try_from(events.len()).map_err(|_| Error::EOVERFLOW)?;