wasmerio / wasmer

🚀 The leading Wasm Runtime supporting WASIX, WASI and Emscripten
https://wasmer.io
MIT License
18.22k stars 769 forks source link

`path_symlink` crashes runtime #4899

Open yagehu opened 2 weeks ago

yagehu commented 2 weeks ago

Describe the bug

Calling path_symlink with a non-directory descriptor and a new_path with only one component crashes Wasmer.

fn main() {
    unsafe {
        let base_fd = 5;
        let fd = wasi::path_open(
            base_fd,
            0,
            "dir/a",
            wasi::OFLAGS_CREAT,
            wasi::RIGHTS_FD_WRITE,
            0,
            0,
        )
        .unwrap();

        wasi::path_symlink("a", fd, "link").unwrap();
    }
}

Wasmer commit: fb9a04bb72d5203b3af4076122486f728fd710b2

Steps to reproduce

Compile the snippet with wasi crate v0.11 and run with wasmer:

cargo build --target wasm32-wasi
wasmer run --mapdir /dir:. target/wasm32-wasi/debug/example.wasm

Expected behavior

The function should return a error code.

Actual behavior

Wasmer panics:

thread 'main' panicked at lib/wasix/src/syscalls/wasi/path_symlink.rs:104:17:
internal error: entered unreachable code: get_parent_inode_at_path returned something other than a Dir or Root
syrusakbary commented 1 week ago

That looks like a bug, the runtime should not have panics. Open to collaborations if you want!