Skip to content

Commit

Permalink
Fix a missing increment in p1-to-p2 adapter
Browse files Browse the repository at this point in the history
This commit fixes a bug in the WASIp1-to-WASIp2 adapter during
`fd_prestat_dir_name` where an iterator variable was forgotten to be
incremented. That means that getting the path for anything other than
the first preopen didn't work correctly.

Closes bytecodealliance#10058
  • Loading branch information
alexcrichton committed Jan 21, 2025
1 parent 3ed4a63 commit d3afa6d
Show file tree
Hide file tree
Showing 7 changed files with 70 additions and 4 deletions.
18 changes: 14 additions & 4 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions crates/test-programs/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -21,3 +21,4 @@ futures = { workspace = true, default-features = false, features = ['alloc'] }
url = { workspace = true }
sha2 = "0.10.2"
base64 = "0.21.0"
wasip2 = { version = "0.14.0", package = 'wasi' }
29 changes: 29 additions & 0 deletions crates/test-programs/src/bin/cli_multiple_preopens.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
use std::str;

fn main() {
dbg!(wasip2::filesystem::preopens::get_directories());
unsafe {
let p3 = wasi::fd_prestat_get(3).unwrap();
let p4 = wasi::fd_prestat_get(4).unwrap();
let p5 = wasi::fd_prestat_get(5).unwrap();
assert_eq!(wasi::fd_prestat_get(6).err().unwrap(), wasi::ERRNO_BADF);

assert_eq!(p3.u.dir.pr_name_len, 2);
assert_eq!(p4.u.dir.pr_name_len, 2);
assert_eq!(p5.u.dir.pr_name_len, 2);

let mut buf = [0; 100];

wasi::fd_prestat_dir_name(3, buf.as_mut_ptr(), buf.len()).unwrap();
assert_eq!(str::from_utf8(&buf[..2]).unwrap(), "/a");
wasi::fd_prestat_dir_name(4, buf.as_mut_ptr(), buf.len()).unwrap();
assert_eq!(str::from_utf8(&buf[..2]).unwrap(), "/b");
wasi::fd_prestat_dir_name(5, buf.as_mut_ptr(), buf.len()).unwrap();
assert_eq!(str::from_utf8(&buf[..2]).unwrap(), "/c");
assert_eq!(
wasi::fd_prestat_dir_name(6, buf.as_mut_ptr(), buf.len()),
Err(wasi::ERRNO_BADF),
);
}
// ..
}
1 change: 1 addition & 0 deletions crates/wasi-preview1-component-adapter/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -404,6 +404,7 @@ impl ImportAlloc {
ImportAlloc::GetPreopenPath { cur, nth, alloc } => {
if align == 1 {
let real_alloc = *nth == *cur;
*cur += 1;
if real_alloc {
alloc.alloc(align, size)
} else {
Expand Down
6 changes: 6 additions & 0 deletions supply-chain/audits.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4547,6 +4547,12 @@ user-id = 1 # Alex Crichton (alexcrichton)
start = "2020-06-03"
end = "2025-12-05"

[[trusted.wasi]]
criteria = "safe-to-deploy"
user-id = 6825 # Dan Gohman (sunfishcode)
start = "2019-07-22"
end = "2026-01-21"

[[trusted.wasm-bindgen]]
criteria = "safe-to-deploy"
user-id = 1 # Alex Crichton (alexcrichton)
Expand Down
7 changes: 7 additions & 0 deletions supply-chain/imports.lock
Original file line number Diff line number Diff line change
Expand Up @@ -1324,6 +1324,13 @@ user-id = 1
user-login = "alexcrichton"
user-name = "Alex Crichton"

[[publisher.wasi]]
version = "0.14.0+wasi-0.2.3"
when = "2025-01-10"
user-id = 6825
user-login = "sunfishcode"
user-name = "Dan Gohman"

[[publisher.wasi-common]]
version = "28.0.0"
when = "2024-12-20"
Expand Down
12 changes: 12 additions & 0 deletions tests/all/cli_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2070,6 +2070,18 @@ after empty
])?;
Ok(())
}

#[test]
fn cli_multiple_preopens() -> Result<()> {
run_wasmtime(&[
"run",
"--dir=/::/a",
"--dir=/::/b",
"--dir=/::/c",
CLI_MULTIPLE_PREOPENS_COMPONENT,
])?;
Ok(())
}
}

#[test]
Expand Down

0 comments on commit d3afa6d

Please sign in to comment.