Skip to content

Commit 25512f3

Browse files
committed
Fix WASI path mapping processing
Filesystem paths can be mapped from the host path to a guest path using the format `<guest-path>::<host-path>`. Previously `strtok` was used to find the `::` delimiter. Unfortunately `strtok` processes each delimiter character individually. This meant that the code was ~equivalent to `strtok(mapping_copy, ":")` which breaks with Windows-style paths (E.g. `C:\my_path\`). To fix this `strstr` is used to search for the exact delimiter.
1 parent f1d03db commit 25512f3

File tree

1 file changed

+12
-2
lines changed

1 file changed

+12
-2
lines changed

core/iwasm/common/wasm_runtime_common.c

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3631,8 +3631,18 @@ wasm_runtime_init_wasi(WASMModuleInstanceCommon *module_inst,
36313631

36323632
bh_memcpy_s(mapping_copy, max_len, map_dir_list[i],
36333633
(uint32)(strlen(map_dir_list[i]) + 1));
3634-
map_mapped = strtok(mapping_copy, "::");
3635-
map_host = strtok(NULL, "::");
3634+
3635+
const char *delim = "::";
3636+
char *delim_pos = strstr(mapping_copy, delim);
3637+
if (delim_pos) {
3638+
*delim_pos = '\0';
3639+
map_mapped = mapping_copy;
3640+
map_host = delim_pos + strlen(delim);
3641+
}
3642+
else {
3643+
map_mapped = NULL;
3644+
map_host = NULL;
3645+
}
36363646

36373647
if (!map_mapped || !map_host) {
36383648
if (error_buf)

0 commit comments

Comments
 (0)