Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion deps/uvwasi/include/uvwasi.h
Original file line numberDiff line numberDiff line change
Expand Up@@ -11,7 +11,7 @@ extern "C" {

#defineUVWASI_VERSION_MAJOR 0
#defineUVWASI_VERSION_MINOR 0
#defineUVWASI_VERSION_PATCH20
#defineUVWASI_VERSION_PATCH21
#defineUVWASI_VERSION_HEX ((UVWASI_VERSION_MAJOR << 16) | \
(UVWASI_VERSION_MINOR << 8) | \
(UVWASI_VERSION_PATCH))
Expand Down
2 changes: 1 addition & 1 deletion deps/uvwasi/src/path_resolver.c
Original file line numberDiff line numberDiff line change
Expand Up@@ -269,7 +269,7 @@ static uvwasi_errno_t uvwasi__normalize_relative_path(
normalized. */
uvwasi_errno_terr;
char*combined;
char*normalized;
char*normalized=NULL;
uvwasi_size_tcombined_len;
uvwasi_size_tfd_path_len;
uvwasi_size_tnorm_len;
Expand Down
43 changes: 37 additions & 6 deletions deps/uvwasi/src/uvwasi.c
Original file line numberDiff line numberDiff line change
Expand Up@@ -1158,7 +1158,7 @@ uvwasi_errno_t uvwasi_fd_pread(uvwasi_t* uvwasi,
offset,
nread);

if (uvwasi == NULL || iovs == NULL || nread == NULL)
if (uvwasi == NULL || (iovs == NULL && iovs_len > 0) || nread == NULL || offset > INT64_MAX)
return UVWASI_EINVAL;

err = uvwasi_fd_table_get(uvwasi->fds,
Expand All@@ -1169,6 +1169,14 @@ uvwasi_errno_t uvwasi_fd_pread(uvwasi_t* uvwasi,
if (err != UVWASI_ESUCCESS)
return err;

// libuv returns EINVAL in this case. To behave consistently with other
// Wasm runtimes, return OK here with a no-op.
if (iovs_len == 0) {
uv_mutex_unlock(&wrap->mutex);
*nread = 0;
return UVWASI_ESUCCESS;
}

err = uvwasi__setup_iovs(uvwasi, &bufs, iovs, iovs_len);
if (err != UVWASI_ESUCCESS) {
uv_mutex_unlock(&wrap->mutex);
Expand DownExpand Up@@ -1282,7 +1290,7 @@ uvwasi_errno_t uvwasi_fd_pwrite(uvwasi_t* uvwasi,
offset,
nwritten);

if (uvwasi == NULL || iovs == NULL || nwritten == NULL)
if (uvwasi == NULL || (iovs == NULL && iovs_len > 0) || nwritten == NULL || offset > INT64_MAX)
return UVWASI_EINVAL;

err = uvwasi_fd_table_get(uvwasi->fds,
Expand All@@ -1293,6 +1301,14 @@ uvwasi_errno_t uvwasi_fd_pwrite(uvwasi_t* uvwasi,
if (err != UVWASI_ESUCCESS)
return err;

// libuv returns EINVAL in this case. To behave consistently with other
// Wasm runtimes, return OK here with a no-op.
if (iovs_len == 0) {
uv_mutex_unlock(&wrap->mutex);
*nwritten = 0;
return UVWASI_ESUCCESS;
}

err = uvwasi__setup_ciovs(uvwasi, &bufs, iovs, iovs_len);
if (err != UVWASI_ESUCCESS) {
uv_mutex_unlock(&wrap->mutex);
Expand DownExpand Up@@ -1332,14 +1348,21 @@ uvwasi_errno_t uvwasi_fd_read(uvwasi_t* uvwasi,
iovs,
iovs_len,
nread);

if (uvwasi == NULL || iovs == NULL || nread == NULL)
if (uvwasi == NULL || (iovs == NULL && iovs_len > 0) || nread == NULL)
return UVWASI_EINVAL;

err = uvwasi_fd_table_get(uvwasi->fds, fd, &wrap, UVWASI_RIGHT_FD_READ, 0);
if (err != UVWASI_ESUCCESS)
return err;

// libuv returns EINVAL in this case. To behave consistently with other
// Wasm runtimes, return OK here with a no-op.
if (iovs_len == 0) {
uv_mutex_unlock(&wrap->mutex);
*nread = 0;
return UVWASI_ESUCCESS;
}

err = uvwasi__setup_iovs(uvwasi, &bufs, iovs, iovs_len);
if (err != UVWASI_ESUCCESS) {
uv_mutex_unlock(&wrap->mutex);
Expand DownExpand Up@@ -1634,13 +1657,21 @@ uvwasi_errno_t uvwasi_fd_write(uvwasi_t* uvwasi,
iovs_len,
nwritten);

if (uvwasi == NULL || iovs == NULL || nwritten == NULL)
if (uvwasi == NULL || (iovs == NULL && iovs_len > 0) || nwritten == NULL)
return UVWASI_EINVAL;

err = uvwasi_fd_table_get(uvwasi->fds, fd, &wrap, UVWASI_RIGHT_FD_WRITE, 0);
if (err != UVWASI_ESUCCESS)
return err;

// libuv returns EINVAL in this case. To behave consistently with other
// Wasm runtimes, return OK here with a no-op.
if (iovs_len == 0) {
uv_mutex_unlock(&wrap->mutex);
*nwritten = 0;
return UVWASI_ESUCCESS;
}

err = uvwasi__setup_ciovs(uvwasi, &bufs, iovs, iovs_len);
if (err != UVWASI_ESUCCESS) {
uv_mutex_unlock(&wrap->mutex);
Expand DownExpand Up@@ -2168,7 +2199,7 @@ uvwasi_errno_t uvwasi_path_readlink(uvwasi_t* uvwasi,

memcpy(buf, req.ptr, len);
buf[len] = '\0';
*bufused = len + 1;
*bufused = len;
uv_fs_req_cleanup(&req);
return UVWASI_ESUCCESS;
}
Expand Down
2 changes: 1 addition & 1 deletion test/wasi/c/create_symlink.c
Original file line numberDiff line numberDiff line change
Expand Up@@ -11,7 +11,7 @@ int main() {

assert(0==symlink(target, linkpath));
assert(readlink(linkpath, readlink_result, result_size) ==
strlen(target)+1);
strlen(target));
assert(0==strcmp(readlink_result, target));

FILE*file=fopen(linkpath, "r");
Expand Down
Binary file modifiedtest/wasi/wasm/create_symlink.wasm
Binary file not shown.