From 006e2c6ed5d8ef3c7ef8398e83c52f1eb2510065 Mon Sep 17 00:00:00 2001 From: cjihrig Date: Fri, 24 Jan 2020 19:28:23 -0500 Subject: [PATCH] add __wasi_poll_oneoff() input validation 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: https://github.com/cjihrig/uvwasi/issues/59 --- src/uvwasi.c | 5 +++++ test/test-einval-input-validation.c | 8 +++++++- test/test-enotsup-apis.c | 1 - 3 files changed, 12 insertions(+), 2 deletions(-) diff --git a/src/uvwasi.c b/src/uvwasi.c index 8e6d38c..3440336 100644 --- a/src/uvwasi.c +++ b/src/uvwasi.c @@ -2246,6 +2246,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; } diff --git a/test/test-einval-input-validation.c b/test/test-einval-input-validation.c index e246ae3..3bb0b75 100644 --- a/test/test-einval-input-validation.c +++ b/test/test-einval-input-validation.c @@ -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; @@ -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)); diff --git a/test/test-enotsup-apis.c b/test/test-enotsup-apis.c index 95bac35..fdf0c0d 100644 --- a/test/test-enotsup-apis.c +++ b/test/test-enotsup-apis.c @@ -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));