diff --git a/deps/uvwasi/include/uvwasi.h b/deps/uvwasi/include/uvwasi.h index 752c3ba3958e7c..7dbcc667793a07 100644 --- a/deps/uvwasi/include/uvwasi.h +++ b/deps/uvwasi/include/uvwasi.h @@ -11,7 +11,7 @@ extern "C" { #define UVWASI_VERSION_MAJOR 0 #define UVWASI_VERSION_MINOR 0 -#define UVWASI_VERSION_PATCH 20 +#define UVWASI_VERSION_PATCH 21 #define UVWASI_VERSION_HEX ((UVWASI_VERSION_MAJOR << 16) | \ (UVWASI_VERSION_MINOR << 8) | \ (UVWASI_VERSION_PATCH)) diff --git a/deps/uvwasi/src/path_resolver.c b/deps/uvwasi/src/path_resolver.c index ec8946b1393d74..deb3f603821f92 100644 --- a/deps/uvwasi/src/path_resolver.c +++ b/deps/uvwasi/src/path_resolver.c @@ -269,7 +269,7 @@ static uvwasi_errno_t uvwasi__normalize_relative_path( normalized. */ uvwasi_errno_t err; char* combined; - char* normalized; + char* normalized = NULL; uvwasi_size_t combined_len; uvwasi_size_t fd_path_len; uvwasi_size_t norm_len; diff --git a/deps/uvwasi/src/uvwasi.c b/deps/uvwasi/src/uvwasi.c index 40162f886fa224..948c1355c9ccf7 100644 --- a/deps/uvwasi/src/uvwasi.c +++ b/deps/uvwasi/src/uvwasi.c @@ -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, @@ -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); @@ -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, @@ -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); @@ -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); @@ -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); @@ -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; } diff --git a/test/wasi/c/create_symlink.c b/test/wasi/c/create_symlink.c index 319b10c6909781..bf9d804753c1dc 100644 --- a/test/wasi/c/create_symlink.c +++ b/test/wasi/c/create_symlink.c @@ -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"); diff --git a/test/wasi/wasm/create_symlink.wasm b/test/wasi/wasm/create_symlink.wasm index 64e120cd5a617b..be824359be6372 100755 Binary files a/test/wasi/wasm/create_symlink.wasm and b/test/wasi/wasm/create_symlink.wasm differ