Skip to content

Commit

Permalink
deps: update to uvwasi 0.0.8
Browse files Browse the repository at this point in the history
This release focuses on improving the robustness of the path
resolution and sandboxing, including adding support for relative
preopen paths.

PR-URL: #33078
Reviewed-By: Gus Caplan <[email protected]>
Reviewed-By: Juan José Arboleda <[email protected]>
Reviewed-By: Anna Henningsen <[email protected]>
  • Loading branch information
cjihrig committed Apr 28, 2020
1 parent 6ca6db1 commit 497ad81
Show file tree
Hide file tree
Showing 9 changed files with 546 additions and 337 deletions.
1 change: 1 addition & 0 deletions deps/uvwasi/include/fd_table.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ struct uvwasi_fd_wrap_t {
uv_file fd;
char* path;
char* real_path;
char* normalized_path;
uvwasi_filetype_t type;
uvwasi_rights_t rights_base;
uvwasi_rights_t rights_inheriting;
Expand Down
6 changes: 3 additions & 3 deletions deps/uvwasi/include/uvwasi.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ extern "C" {

#define UVWASI_VERSION_MAJOR 0
#define UVWASI_VERSION_MINOR 0
#define UVWASI_VERSION_PATCH 6
#define UVWASI_VERSION_PATCH 8
#define UVWASI_VERSION_HEX ((UVWASI_VERSION_MAJOR << 16) | \
(UVWASI_VERSION_MINOR << 8) | \
(UVWASI_VERSION_PATCH))
Expand Down Expand Up @@ -66,7 +66,7 @@ typedef struct uvwasi_options_s {
const uvwasi_mem_t* allocator;
} uvwasi_options_t;

// Embedder API.
/* Embedder API. */
uvwasi_errno_t uvwasi_init(uvwasi_t* uvwasi, uvwasi_options_t* options);
void uvwasi_destroy(uvwasi_t* uvwasi);
uvwasi_errno_t uvwasi_embedder_remap_fd(uvwasi_t* uvwasi,
Expand All @@ -75,7 +75,7 @@ uvwasi_errno_t uvwasi_embedder_remap_fd(uvwasi_t* uvwasi,
const char* uvwasi_embedder_err_code_to_string(uvwasi_errno_t code);


// WASI system call API.
/* WASI system call API. */
uvwasi_errno_t uvwasi_args_get(uvwasi_t* uvwasi, char** argv, char* argv_buf);
uvwasi_errno_t uvwasi_args_sizes_get(uvwasi_t* uvwasi,
size_t* argc,
Expand Down
2 changes: 1 addition & 1 deletion deps/uvwasi/include/wasi_types.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
#include <stddef.h>
#include <stdint.h>

/* API: https://github.com/WebAssembly/WASI/blob/master/phases/unstable/docs/wasi_unstable_preview0.md */
/* API: https://github.com/WebAssembly/WASI/blob/master/phases/snapshot/docs.md */

typedef uint8_t uvwasi_advice_t;
#define UVWASI_ADVICE_NORMAL 0
Expand Down
4 changes: 2 additions & 2 deletions deps/uvwasi/src/clocks.c
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ uvwasi_errno_t uvwasi__clock_gettime_thread_cputime(uvwasi_timestamp_t* time) {
UVWASI__WIN_TIME_AND_RETURN(GetCurrentThread(), *time);
#elif defined(__APPLE__)
UVWASI__OSX_THREADTIME_AND_RETURN(*time);
#elif defined(CLOCK_THREAD_CPUTIME_ID) && !defined(__sun)
#elif defined(CLOCK_THREAD_CPUTIME_ID) && !defined(__sun) && !defined(__PASE__)
UVWASI__CLOCK_GETTIME_AND_RETURN(CLOCK_THREAD_CPUTIME_ID, *time);
#else
# if defined(RUSAGE_LWP)
Expand Down Expand Up @@ -185,7 +185,7 @@ uvwasi_errno_t uvwasi__clock_getres_thread_cputime(uvwasi_timestamp_t* time) {
UVWASI__WIN_GETRES_AND_RETURN(*time);
#elif defined(__APPLE__)
UVWASI__SLOW_GETRES_AND_RETURN(*time);
#elif defined(CLOCK_THREAD_CPUTIME_ID) && !defined(__sun)
#elif defined(CLOCK_THREAD_CPUTIME_ID) && !defined(__sun) && !defined(__PASE__)
UVWASI__CLOCK_GETTIME_AND_RETURN(CLOCK_THREAD_CPUTIME_ID, *time);
#elif defined(RUSAGE_THREAD) || defined(RUSAGE_LWP)
UVWASI__SLOW_GETRES_AND_RETURN(*time);
Expand Down
19 changes: 17 additions & 2 deletions deps/uvwasi/src/fd_table.c
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

#include "uv.h"
#include "fd_table.h"
#include "path_resolver.h"
#include "wasi_types.h"
#include "wasi_rights.h"
#include "uv_mapping.h"
Expand Down Expand Up @@ -75,20 +76,33 @@ uvwasi_errno_t uvwasi_fd_table_insert(uvwasi_t* uvwasi,
char* mp_copy;
size_t rp_len;
char* rp_copy;
char* np_copy;

mp_len = strlen(mapped_path);
rp_len = strlen(real_path);
/* Reserve room for the mapped path, real path, and normalized mapped path. */
entry = (struct uvwasi_fd_wrap_t*)
uvwasi__malloc(uvwasi, sizeof(*entry) + mp_len + rp_len + 2);
if (entry == NULL) return UVWASI_ENOMEM;
uvwasi__malloc(uvwasi, sizeof(*entry) + mp_len + mp_len + rp_len + 3);
if (entry == NULL)
return UVWASI_ENOMEM;

mp_copy = (char*)(entry + 1);
rp_copy = mp_copy + mp_len + 1;
np_copy = rp_copy + rp_len + 1;
memcpy(mp_copy, mapped_path, mp_len);
mp_copy[mp_len] = '\0';
memcpy(rp_copy, real_path, rp_len);
rp_copy[rp_len] = '\0';

/* Calculate the normalized version of the mapped path, as it will be used for
any path calculations on this fd. Use the length of the mapped path as an
upper bound for the normalized path length. */
err = uvwasi__normalize_path(mp_copy, mp_len, np_copy, mp_len);
if (err) {
uvwasi__free(uvwasi, entry);
goto exit;
}

uv_rwlock_wrlock(&table->rwlock);

/* Check that there is room for a new item. If there isn't, grow the table. */
Expand Down Expand Up @@ -138,6 +152,7 @@ uvwasi_errno_t uvwasi_fd_table_insert(uvwasi_t* uvwasi,
entry->fd = fd;
entry->path = mp_copy;
entry->real_path = rp_copy;
entry->normalized_path = np_copy;
entry->type = type;
entry->rights_base = rights_base;
entry->rights_inheriting = rights_inheriting;
Expand Down
Loading

0 comments on commit 497ad81

Please sign in to comment.