nodejs / uvwasi

WASI syscall API built atop libuv
MIT License
222 stars 48 forks source link

`path_open` does not respect trailing slashes #267

Closed yagehu closed 1 month ago

yagehu commented 1 month ago

Both these snippets should fail with notdir because the path contains a trailing slash. This behavior is consistent among Linux host, Wasmtime, WAMR, WasmEdge. Node however, successfully opens the file.

#include <fcntl.h>
#include <stdio.h>

int main() {
    int fd = open("file/", O_RDONLY);
    if (fd < 0) {
        perror("open");
        return 1;
    }

    return 0;
}
fn main() {
    unsafe {
        let base_fd = 3;
        let fd = wasi::path_open(base_fd, 0, "file/", 0, wasi::RIGHTS_FD_READ, 0, 0).unwrap();

        eprintln!("fd {fd}");
    }
}
yagehu commented 1 month ago

Just want to highlight a case this behavior is desired. A symlink may point to a path with trailing slash to make sure it's a directory and not a file.