Skip to content

Commit

Permalink
add __wasi_poll_oneoff() input validation
Browse files Browse the repository at this point in the history
snapshot_preview2 added the constraint that poll_oneoff() should
return EINVAL if nsubscriptions is zero. Even though poll_oneoff()
isn't implemented yet, this commit adds the necessary input
validation.

Refs: #59
  • Loading branch information
cjihrig committed Apr 20, 2020
1 parent fbec070 commit 7ebe368
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 2 deletions.
5 changes: 5 additions & 0 deletions src/uvwasi.c
Original file line number Diff line number Diff line change
Expand Up @@ -2259,6 +2259,11 @@ uvwasi_errno_t uvwasi_poll_oneoff(uvwasi_t* uvwasi,
uvwasi_event_t* out,
size_t nsubscriptions,
size_t* nevents) {
if (uvwasi == NULL || in == NULL || out == NULL ||
nsubscriptions == 0 || nevents == NULL) {
return UVWASI_EINVAL;
}

/* TODO(cjihrig): Implement this. */
return UVWASI_ENOTSUP;
}
Expand Down
8 changes: 7 additions & 1 deletion test/test-einval-input-validation.c
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ int main(void) {
uvwasi_prestat_t test_prestat;
uvwasi_dircookie_t test_dircookie = 0;
uvwasi_filesize_t test_filesize;
uvwasi_subscription_t test_sub;
uvwasi_event_t test_event;
uvwasi_fd_t test_fd;

test_void = (void*) &test_fdstat;
Expand Down Expand Up @@ -145,7 +147,11 @@ int main(void) {
CHECK(uvwasi_path_unlink_file(NULL, 3, test_str, 10));
CHECK(uvwasi_path_unlink_file(&uvw, 3, NULL, 10));

/* TODO(cjihrig): Add uvwasi_poll_oneoff() tests. */
CHECK(uvwasi_poll_oneoff(NULL, &test_sub, &test_event, 5, &test_size));
CHECK(uvwasi_poll_oneoff(&uvw, NULL, &test_event, 5, &test_size));
CHECK(uvwasi_poll_oneoff(&uvw, &test_sub, NULL, 5, &test_size));
CHECK(uvwasi_poll_oneoff(&uvw, &test_sub, &test_event, 0, &test_size));
CHECK(uvwasi_poll_oneoff(&uvw, &test_sub, &test_event, 5, NULL));

CHECK(uvwasi_proc_raise(NULL, UVWASI_SIGUSR2));

Expand Down
1 change: 0 additions & 1 deletion test/test-enotsup-apis.c
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@

int main(void) {
/* TODO(cjihrig): This test is intended to be temporary. */
assert(UVWASI_ENOTSUP == uvwasi_poll_oneoff(NULL, NULL, NULL, 0, NULL));
assert(UVWASI_ENOTSUP == uvwasi_sock_recv(NULL, 0, NULL, 0, 0, NULL, NULL));
assert(UVWASI_ENOTSUP == uvwasi_sock_send(NULL, 0, NULL, 0, 0, NULL));
assert(UVWASI_ENOTSUP == uvwasi_sock_shutdown(NULL, 0, 0));
Expand Down

0 comments on commit 7ebe368

Please sign in to comment.