Skip to content

Commit 006e2c6

Browse files
committed
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: #59
1 parent 9b39500 commit 006e2c6

File tree

3 files changed

+12
-2
lines changed

3 files changed

+12
-2
lines changed

src/uvwasi.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2246,6 +2246,11 @@ uvwasi_errno_t uvwasi_poll_oneoff(uvwasi_t* uvwasi,
22462246
uvwasi_event_t* out,
22472247
size_t nsubscriptions,
22482248
size_t* nevents) {
2249+
if (uvwasi == NULL || in == NULL || out == NULL ||
2250+
nsubscriptions == 0 || nevents == NULL) {
2251+
return UVWASI_EINVAL;
2252+
}
2253+
22492254
/* TODO(cjihrig): Implement this. */
22502255
return UVWASI_ENOTSUP;
22512256
}

test/test-einval-input-validation.c

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@ int main(void) {
2020
uvwasi_prestat_t test_prestat;
2121
uvwasi_dircookie_t test_dircookie = 0;
2222
uvwasi_filesize_t test_filesize;
23+
uvwasi_subscription_t test_sub;
24+
uvwasi_event_t test_event;
2325
uvwasi_fd_t test_fd;
2426

2527
test_void = (void*) &test_fdstat;
@@ -145,7 +147,11 @@ int main(void) {
145147
CHECK(uvwasi_path_unlink_file(NULL, 3, test_str, 10));
146148
CHECK(uvwasi_path_unlink_file(&uvw, 3, NULL, 10));
147149

148-
/* TODO(cjihrig): Add uvwasi_poll_oneoff() tests. */
150+
CHECK(uvwasi_poll_oneoff(NULL, &test_sub, &test_event, 5, &test_size));
151+
CHECK(uvwasi_poll_oneoff(&uvw, NULL, &test_event, 5, &test_size));
152+
CHECK(uvwasi_poll_oneoff(&uvw, &test_sub, NULL, 5, &test_size));
153+
CHECK(uvwasi_poll_oneoff(&uvw, &test_sub, &test_event, 0, &test_size));
154+
CHECK(uvwasi_poll_oneoff(&uvw, &test_sub, &test_event, 5, NULL));
149155

150156
CHECK(uvwasi_proc_raise(NULL, UVWASI_SIGUSR2));
151157

test/test-enotsup-apis.c

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33

44
int main(void) {
55
/* TODO(cjihrig): This test is intended to be temporary. */
6-
assert(UVWASI_ENOTSUP == uvwasi_poll_oneoff(NULL, NULL, NULL, 0, NULL));
76
assert(UVWASI_ENOTSUP == uvwasi_sock_recv(NULL, 0, NULL, 0, 0, NULL, NULL));
87
assert(UVWASI_ENOTSUP == uvwasi_sock_send(NULL, 0, NULL, 0, 0, NULL));
98
assert(UVWASI_ENOTSUP == uvwasi_sock_shutdown(NULL, 0, 0));

0 commit comments

Comments
 (0)