From bc2d8959ddb74d4cc5930fa28b394d8f53db1079 Mon Sep 17 00:00:00 2001 From: Yage Hu Date: Sun, 10 Dec 2023 22:16:58 -0800 Subject: [PATCH] Handle ambiguous fstflags on fd_filestat_set_times (#2892) It's possible to set both `atim` and `atim_now` in the `fstflags` parameter. Same goes for `mtin` and `mtim_now`. However, it's ambiguous which time should be set in these two cases. This commit checks this and returns `EINVAL`. --- .../libc-wasi/sandboxed-system-primitives/src/posix.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/core/iwasm/libraries/libc-wasi/sandboxed-system-primitives/src/posix.c b/core/iwasm/libraries/libc-wasi/sandboxed-system-primitives/src/posix.c index b59035f3..9819c92f 100644 --- a/core/iwasm/libraries/libc-wasi/sandboxed-system-primitives/src/posix.c +++ b/core/iwasm/libraries/libc-wasi/sandboxed-system-primitives/src/posix.c @@ -1891,7 +1891,13 @@ wasmtime_ssp_fd_filestat_set_times(wasm_exec_env_t exec_env, if ((fstflags & ~(__WASI_FILESTAT_SET_ATIM | __WASI_FILESTAT_SET_ATIM_NOW | __WASI_FILESTAT_SET_MTIM | __WASI_FILESTAT_SET_MTIM_NOW)) - != 0) + != 0 + || (fstflags + & (__WASI_FILESTAT_SET_ATIM | __WASI_FILESTAT_SET_ATIM_NOW)) + == (__WASI_FILESTAT_SET_ATIM | __WASI_FILESTAT_SET_ATIM_NOW) + || (fstflags + & (__WASI_FILESTAT_SET_MTIM | __WASI_FILESTAT_SET_MTIM_NOW)) + == (__WASI_FILESTAT_SET_MTIM | __WASI_FILESTAT_SET_MTIM_NOW)) return __WASI_EINVAL; struct fd_object *fo;