Repository: tetratelabs/wazero (go)

Issue:
`path_open` with an empty path should fail
**Describe the bug**

Calling `path_open` on an empty path fails on host Linux as well as other runtimes (Wasmtime, Node, WAMR, WasmEdge, Wasmer). But Wazero succeeds and returns a fd.

As a reference, [POSIX](http://pubs.opengroup.org/onlinepubs/9699919799/basedefs/V1_chap04.html) specifies that:

> A null pathname shall not be successfully resolved.

A rust example that uses `wasi` crate `0.11`.

```rust
fn main() {
    unsafe {
        let fd = wasi::path_open(
            3,
            0,
            "",
            0,
            wasi::RIGHTS_FD_READ | wasi::RIGHTS_FD_WRITE | wasi::RIGHTS_FD_SEEK,
            0,
            0,
        )
        .unwrap();

        eprintln!("fd: {fd}");
    }
}
```

**Expected behavior**
Wazero should error and not return a fd.


**Environment (please complete the relevant information):**

- Go version: go1.21.1 darwin/amd64
- wazero Version: d4a49031b671b59fb832c95741df63b96f144104
- Host architecture: amd64
- Runtime mode: [e.g. interpreter or compiler]


Pull request description:
Disallow empty path on path_open
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

Patch:
diff --git a/imports/wasi_snapshot_preview1/fs.go b/imports/wasi_snapshot_preview1/fs.go
index 384036a2..a3559e5d 100644
--- a/imports/wasi_snapshot_preview1/fs.go
+++ b/imports/wasi_snapshot_preview1/fs.go
@@ -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
 


Test patch:
diff --git a/imports/wasi_snapshot_preview1/fs_test.go b/imports/wasi_snapshot_preview1/fs_test.go
index 9743d748..037d34d6 100644
--- a/imports/wasi_snapshot_preview1/fs_test.go
+++ b/imports/wasi_snapshot_preview1/fs_test.go
@@ -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)
 `,
 		},
 		{