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

path_open sometimes ignores trailing slash #4820

Closed
yagehu opened this issue Jun 7, 2024 · 0 comments · Fixed by #4821
Closed

path_open sometimes ignores trailing slash #4820

yagehu opened this issue Jun 7, 2024 · 0 comments · Fixed by #4821

Comments

@yagehu
Copy link
Contributor

yagehu commented Jun 7, 2024

Describe the bug

path_open should error if the input path ends with a / but points to an existing regular file. This is the behavior on native Linux, WAMR, WasmEdge, Wasmtime, and Wazero.

Steps to reproduce

This standalone snippet can be added to wasi-fyi test suite.

#[link(wasm_import_module = "wasi_snapshot_preview1")]
extern "C" {
    pub fn path_open(
        fd: i32,
        dirflags: i32,
        path: i32,
        path_len: i32,
        oflags: i32,
        fs_rights_base: i64,
        fs_rights_inheriting: i64,
        fdflags: i32,
        result_fd: i32,
    ) -> i32;
}

const ERRNO_SUCCESS: i32 = 0;
const ERRNO_NOTDIR: i32 = 54;
const RIGHTS_FD_READ: i64 = 2;

fn main() {
    unsafe {
        let fd = 5;
        let path_ok = "fyi/fs_open_trailing_slash.dir/file";
        let path_bad = "fyi/fs_open_trailing_slash.dir/file/";
        let errno = path_open(
            fd,
            0,
            path_ok.as_ptr() as i32,
            path_ok.len() as i32,
            0,
            RIGHTS_FD_READ,
            0,
            0,
            1024,
        );
        assert_eq!(
            errno, ERRNO_SUCCESS,
            "opening a file without a trailing slash works"
        );

        let errno = path_open(
            fd,
            0,
            path_bad.as_ptr() as i32,
            path_bad.len() as i32,
            0,
            RIGHTS_FD_READ,
            0,
            0,
            1024,
        );
        assert_eq!(
            errno, ERRNO_NOTDIR,
            "opening a regular file with a trailing slash should fail"
        );
    }
}

Expected behavior

path_open should error with notdir (54).

Actual behavior

path_open succeeds.

Additional context

This issue is not present when compiled with wasi-sdk. Probably because wasi-sdk performs this check.

yagehu added a commit to yagehu/wasmer that referenced this issue Jun 7, 2024
This commit fixes `path_open` sometimes ignoring the trailing slash.  On
host Linux and other runtimes, opening an existing file with a path
containing a trailing slash fails, but wasmer succeeds.

fixes wasmerio#4820
@yagehu yagehu changed the title path_open does not respect trailing slashes path_open sometimes ignores trailing slash Jun 7, 2024
yagehu added a commit to yagehu/wasmer that referenced this issue Jun 8, 2024
This commit fixes `path_open` sometimes ignoring the trailing slash.  On
host Linux and other runtimes, opening an existing file with a path
containing a trailing slash fails, but wasmer succeeds.

fixes wasmerio#4820
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