From 6e9aaff1d393b493c79904d754a21107621bbafe Mon Sep 17 00:00:00 2001 From: cjihrig Date: Tue, 5 May 2020 10:09:39 -0400 Subject: [PATCH] wasi: fix poll_oneoff memory interface The WASM memory interfacing logic was wrong (particularly around the size of __wasi_subscription_t). This commit fixes the logic. --- src/node_wasi.cc | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/src/node_wasi.cc b/src/node_wasi.cc index 0330656b29e926..0ab07b58f055d4 100644 --- a/src/node_wasi.cc +++ b/src/node_wasi.cc @@ -1446,21 +1446,21 @@ void WASI::PollOneoff(const FunctionCallbackInfo& args) { } for (uint32_t i = 0; i < nsubscriptions; ++i) { - uvwasi_subscription_t sub = in[i]; - wasi->readUInt64(memory, &sub.userdata, in_ptr); - wasi->readUInt8(memory, &sub.type, in_ptr + 8); - - if (sub.type == UVWASI_EVENTTYPE_CLOCK) { - wasi->readUInt32(memory, &sub.u.clock.clock_id, in_ptr + 16); - wasi->readUInt64(memory, &sub.u.clock.timeout, in_ptr + 24); - wasi->readUInt64(memory, &sub.u.clock.precision, in_ptr + 32); - wasi->readUInt16(memory, &sub.u.clock.flags, in_ptr + 40); - } else if (sub.type == UVWASI_EVENTTYPE_FD_READ || - sub.type == UVWASI_EVENTTYPE_FD_WRITE) { - wasi->readUInt32(memory, &sub.u.fd_readwrite.fd, in_ptr + 16); + uvwasi_subscription_t* sub = &in[i]; + wasi->readUInt64(memory, &sub->userdata, in_ptr); + wasi->readUInt8(memory, &sub->type, in_ptr + 8); + + if (sub->type == UVWASI_EVENTTYPE_CLOCK) { + wasi->readUInt32(memory, &sub->u.clock.clock_id, in_ptr + 16); + wasi->readUInt64(memory, &sub->u.clock.timeout, in_ptr + 24); + wasi->readUInt64(memory, &sub->u.clock.precision, in_ptr + 32); + wasi->readUInt16(memory, &sub->u.clock.flags, in_ptr + 40); + } else if (sub->type == UVWASI_EVENTTYPE_FD_READ || + sub->type == UVWASI_EVENTTYPE_FD_WRITE) { + wasi->readUInt32(memory, &sub->u.fd_readwrite.fd, in_ptr + 16); } - in_ptr += 56; + in_ptr += 48; } size_t nevents;