Skip to content

Commit

Permalink
Disallow empty path on path_open
Browse files Browse the repository at this point in the history
This commit makes `path_open` return `inval` when passed an empty path.
This behavior is consistent with other Wasm runtimes (Wasmtime, Wasmer,
Node, WAMR, WasmEdge).

fixes #2222

Signed-off-by: Yage Hu <me@huyage.dev>
  • Loading branch information
yagehu committed May 28, 2024
1 parent d4a4903 commit 14dbba2
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 0 deletions.
4 changes: 4 additions & 0 deletions imports/wasi_snapshot_preview1/fs.go
Original file line number Diff line number Diff line change
Expand Up @@ -1596,6 +1596,10 @@ func pathOpenFn(_ context.Context, mod api.Module, params []uint64) experimental
return errno
}

if pathLen == 0 {
return experimentalsys.EINVAL
}

fileOpenFlags := openFlags(dirflags, oflags, fdflags, rights)
isDir := fileOpenFlags&experimentalsys.O_DIRECTORY != 0

Expand Down
11 changes: 11 additions & 0 deletions imports/wasi_snapshot_preview1/fs_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4095,6 +4095,17 @@ func Test_pathOpen_Errors(t *testing.T) {
expectedLog: `
==> wasi_snapshot_preview1.path_open(fd=3,dirflags=,path=OOM(65536,4),oflags=,fs_rights_base=,fs_rights_inheriting=,fdflags=)
<== (opened_fd=,errno=EFAULT)
`,
},
{
name: "empty path",
fd: sys.FdPreopen,
path: 0,
pathLen: 0,
expectedErrno: wasip1.ErrnoInval,
expectedLog: `
==> wasi_snapshot_preview1.path_open(fd=3,dirflags=,path=,oflags=,fs_rights_base=,fs_rights_inheriting=,fdflags=)
<== (opened_fd=,errno=EINVAL)
`,
},
{
Expand Down

0 comments on commit 14dbba2

Please sign in to comment.