Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

uvwasi accepts malformed path containing null byte #265

Closed
yagehu opened this issue May 28, 2024 · 0 comments · Fixed by #266
Closed

uvwasi accepts malformed path containing null byte #265

yagehu opened this issue May 28, 2024 · 0 comments · Fixed by #266

Comments

@yagehu
Copy link
Contributor

yagehu commented May 28, 2024

Calling path_open in uvwasi with a path that contains null byte does not error. Here's an example:

fn main() {
    unsafe {
        let bytes = [18u8, 110u8, 0];
        let path = String::from_utf8(bytes.to_vec()).unwrap();
        let fd = wasi::path_open(
            3,
            0,
            &path,
            wasi::OFLAGS_CREAT | wasi::OFLAGS_EXCL | wasi::OFLAGS_TRUNC,
            wasi::RIGHTS_FD_READ | wasi::RIGHTS_FD_WRITE | wasi::RIGHTS_FD_SEEK,
            0,
            wasi::FDFLAGS_APPEND | wasi::FDFLAGS_NONBLOCK,
        )
        .unwrap();

        eprintln!("fd: {errno}");
    }
}

This Rust example depends on wasi crate v0.11.

On other runtimes, this example fails with inval. But Node succeeds, creating a file with a 2-byte filename.

@yagehu yagehu changed the title uvwasi accepts malformed path containing 0u8 uvwasi accepts malformed path containing null byte May 28, 2024
yagehu added a commit to yagehu/uvwasi that referenced this issue May 28, 2024
This commit adds a check when resolving path such that any null bytes in
the input path causes errno `inval`.  This is consistent with other
runtimes like Wasmtime, Wasmer, Wazero, WasmEdge, and WAMR.

fixes nodejs#265

Signed-off-by: Yage Hu <me@huyage.dev>
mhdawson pushed a commit that referenced this issue Jun 3, 2024
This commit adds a check when resolving path such that any null bytes in
the input path causes errno `inval`.  This is consistent with other
runtimes like Wasmtime, Wasmer, Wazero, WasmEdge, and WAMR.

fixes #265

Signed-off-by: Yage Hu <me@huyage.dev>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant