Преглед на файлове

Portably handle `fd_advise` on directory fd (#2875)

This commit adds a check to `fd_advise`.  If the fd is a directory,
return `ebadf`.  This brings iwasm in line with Wasmtime's behavior.
WASI folks have stated that fd_advise should not work on directories
as this is a Linux-specific behavior:
https://github.com/bytecodealliance/wasmtime/issues/6505#issuecomment-1574122949
Yage Hu преди 2 години
родител
ревизия
0b332d8987
променени са 1 файла, в които са добавени 5 реда и са изтрити 0 реда
  1. 5 0
      core/iwasm/libraries/libc-wasi/sandboxed-system-primitives/src/posix.c

+ 5 - 0
core/iwasm/libraries/libc-wasi/sandboxed-system-primitives/src/posix.c

@@ -1155,6 +1155,11 @@ wasmtime_ssp_fd_advise(wasm_exec_env_t exec_env, struct fd_table *curfds,
     if (error != 0)
         return error;
 
+    if (fo->type == __WASI_FILETYPE_DIRECTORY) {
+        fd_object_release(exec_env, fo);
+        return __WASI_EBADF;
+    }
+
     error = os_fadvise(fo->file_handle, offset, len, advice);
 
     fd_object_release(exec_env, fo);