mirror of
https://github.com/mii443/wasmer.git
synced 2025-12-03 03:08:22 +00:00
Merge pull request #4821 from yagehu/open-trailing-slash
Fix `path_open` sometimes ignoring trailing slash
This commit is contained in:
@@ -205,6 +205,8 @@ pub(crate) fn path_open_internal(
|
||||
|
||||
open_options.options(minimum_rights.clone());
|
||||
|
||||
let orig_path = path;
|
||||
|
||||
let inode = if let Ok(inode) = maybe_inode {
|
||||
// Happy path, we found the file we're trying to open
|
||||
let processing_inode = inode.clone();
|
||||
@@ -228,7 +230,7 @@ pub(crate) fn path_open_internal(
|
||||
assert!(handle.is_some());
|
||||
return Ok(Ok(*special_fd));
|
||||
}
|
||||
if o_flags.contains(Oflags::DIRECTORY) {
|
||||
if o_flags.contains(Oflags::DIRECTORY) || orig_path.ends_with('/') {
|
||||
return Ok(Err(Errno::Notdir));
|
||||
}
|
||||
|
||||
|
||||
57
tests/wasi-fyi/fs_open_trailing_slash.rs
Normal file
57
tests/wasi-fyi/fs_open_trailing_slash.rs
Normal file
@@ -0,0 +1,57 @@
|
||||
#[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"
|
||||
);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user