|
8 | 8 |
|
9 | 9 | #include "uv.h"
|
10 | 10 | #include "fd_table.h"
|
| 11 | +#include "path_resolver.h" |
11 | 12 | #include "wasi_types.h"
|
12 | 13 | #include "wasi_rights.h"
|
13 | 14 | #include "uv_mapping.h"
|
@@ -75,20 +76,33 @@ uvwasi_errno_t uvwasi_fd_table_insert(uvwasi_t* uvwasi,
|
75 | 76 | char* mp_copy;
|
76 | 77 | size_t rp_len;
|
77 | 78 | char* rp_copy;
|
| 79 | + char* np_copy; |
78 | 80 |
|
79 | 81 | mp_len = strlen(mapped_path);
|
80 | 82 | rp_len = strlen(real_path);
|
| 83 | + /* Reserve room for the mapped path, real path, and normalized mapped path. */ |
81 | 84 | entry = (struct uvwasi_fd_wrap_t*)
|
82 |
| - uvwasi__malloc(uvwasi, sizeof(*entry) + mp_len + rp_len + 2); |
83 |
| - if (entry == NULL) return UVWASI_ENOMEM; |
| 85 | + uvwasi__malloc(uvwasi, sizeof(*entry) + mp_len + mp_len + rp_len + 3); |
| 86 | + if (entry == NULL) |
| 87 | + return UVWASI_ENOMEM; |
84 | 88 |
|
85 | 89 | mp_copy = (char*)(entry + 1);
|
86 | 90 | rp_copy = mp_copy + mp_len + 1;
|
| 91 | + np_copy = rp_copy + rp_len + 1; |
87 | 92 | memcpy(mp_copy, mapped_path, mp_len);
|
88 | 93 | mp_copy[mp_len] = '\0';
|
89 | 94 | memcpy(rp_copy, real_path, rp_len);
|
90 | 95 | rp_copy[rp_len] = '\0';
|
91 | 96 |
|
| 97 | + /* Calculate the normalized version of the mapped path, as it will be used for |
| 98 | + any path calculations on this fd. Use the length of the mapped path as an |
| 99 | + upper bound for the normalized path length. */ |
| 100 | + err = uvwasi__normalize_path(mp_copy, mp_len, np_copy, mp_len); |
| 101 | + if (err) { |
| 102 | + uvwasi__free(uvwasi, entry); |
| 103 | + goto exit; |
| 104 | + } |
| 105 | + |
92 | 106 | uv_rwlock_wrlock(&table->rwlock);
|
93 | 107 |
|
94 | 108 | /* Check that there is room for a new item. If there isn't, grow the table. */
|
@@ -138,6 +152,7 @@ uvwasi_errno_t uvwasi_fd_table_insert(uvwasi_t* uvwasi,
|
138 | 152 | entry->fd = fd;
|
139 | 153 | entry->path = mp_copy;
|
140 | 154 | entry->real_path = rp_copy;
|
| 155 | + entry->normalized_path = np_copy; |
141 | 156 | entry->type = type;
|
142 | 157 | entry->rights_base = rights_base;
|
143 | 158 | entry->rights_inheriting = rights_inheriting;
|
|
0 commit comments