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 tetratelabs#2222
  • Loading branch information
yagehu committed May 28, 2024
1 parent d4a4903 commit d3f6303
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
5 changes: 4 additions & 1 deletion imports/wasi_snapshot_preview1/fs.go
Original file line number Diff line number Diff line change
Expand Up @@ -1581,7 +1581,6 @@ func pathOpenFn(_ context.Context, mod api.Module, params []uint64) experimental

path := uint32(params[2])
pathLen := uint32(params[3])

oflags := uint16(params[4])

rights := uint32(params[5])
Expand All @@ -1596,6 +1595,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 d3f6303

Please sign in to comment.