Skip to content

Commit

Permalink
Forbid empty poll list.
Browse files Browse the repository at this point in the history
  • Loading branch information
badeend committed Jan 24, 2024
1 parent d9a9842 commit 537b3f6
Show file tree
Hide file tree
Showing 7 changed files with 28 additions and 11 deletions.
4 changes: 4 additions & 0 deletions crates/test-programs/src/bin/preview2_pollable_traps.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
fn main() {
// Polling an empty list should trap:
test_programs::wasi::io::poll::poll(&[]);
}
5 changes: 3 additions & 2 deletions crates/wasi-http/wit/deps/io/poll.wit
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,9 @@ interface poll {
/// The result `list<u32>` contains one or more indices of handles in the
/// argument list that is ready for I/O.
///
/// If the list contains more elements than can be indexed with a `u32`
/// value, this function traps.
/// This function traps if either:
/// - the list is empty, or:
/// - the list contains more elements than can be indexed with a `u32` value.
///
/// A timeout can be implemented by adding a pollable from the
/// wasi-clocks API to the list.
Expand Down
5 changes: 2 additions & 3 deletions crates/wasi/src/preview2/poll.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use crate::preview2::{bindings::io::poll, WasiView};
use anyhow::Result;
use anyhow::{anyhow, Result};
use futures::Future;
use smallvec::{smallvec, SmallVec};
use std::{
Expand Down Expand Up @@ -155,8 +155,7 @@ impl PollableResource {
impl<T: WasiView> poll::Host for T {
async fn poll(&mut self, pollables: Vec<Resource<PollableResource>>) -> Result<Vec<u32>> {
if pollables.is_empty() {
futures::future::pending::<()>().await;
unreachable!();
return Err(anyhow!("empty poll list"));
}

type PollableRep = u32;
Expand Down
12 changes: 10 additions & 2 deletions crates/wasi/tests/all/async_.rs
Original file line number Diff line number Diff line change
Expand Up @@ -355,8 +355,16 @@ async fn preview2_stream_pollable_traps() {
)
}
#[test_log::test(tokio::test(flavor = "multi_thread"))]
async fn preview2_pollable() {
run(PREVIEW2_POLLABLE_COMPONENT, false).await.unwrap()
async fn preview2_pollable_correct() {
run(PREVIEW2_POLLABLE_CORRECT_COMPONENT, false)
.await
.unwrap()
}
#[test_log::test(tokio::test(flavor = "multi_thread"))]
async fn preview2_pollable_traps() {
run(PREVIEW2_POLLABLE_TRAPS_COMPONENT, false)
.await
.unwrap_err();
}
#[test_log::test(tokio::test(flavor = "multi_thread"))]
async fn preview2_adapter_badfd() {
Expand Down
8 changes: 6 additions & 2 deletions crates/wasi/tests/all/sync.rs
Original file line number Diff line number Diff line change
Expand Up @@ -294,8 +294,12 @@ fn preview2_stream_pollable_traps() {
)
}
#[test_log::test]
fn preview2_pollable() {
run(PREVIEW2_POLLABLE_COMPONENT, false).unwrap()
fn preview2_pollable_correct() {
run(PREVIEW2_POLLABLE_CORRECT_COMPONENT, false).unwrap()
}
#[test_log::test]
fn preview2_pollable_traps() {
run(PREVIEW2_POLLABLE_TRAPS_COMPONENT, false).unwrap_err();
}
#[test_log::test]
fn preview2_adapter_badfd() {
Expand Down
5 changes: 3 additions & 2 deletions crates/wasi/wit/deps/io/poll.wit
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,9 @@ interface poll {
/// The result `list<u32>` contains one or more indices of handles in the
/// argument list that is ready for I/O.
///
/// If the list contains more elements than can be indexed with a `u32`
/// value, this function traps.
/// This function traps if either:
/// - the list is empty, or:
/// - the list contains more elements than can be indexed with a `u32` value.
///
/// A timeout can be implemented by adding a pollable from the
/// wasi-clocks API to the list.
Expand Down

0 comments on commit 537b3f6

Please sign in to comment.