WebAssembly / wasi-filesystem

Filesystem API for WASI
Other
180 stars 19 forks source link

No st_mode from stat? #34

Open corwin-of-amber opened 4 years ago

corwin-of-amber commented 4 years ago

The internal struct used by stat calls does not have a field for the mode of the file (read/write/execute bits), and stat, lstat, fstat, fstatat all return zeros for these bits. The implementer of the API has no control over that.

https://github.com/CraneStation/wasi-libc/blob/12f5832b45c7450f8320db271334081247191d58/libc-bottom-half/headers/public/wasi/api.h#L955

Most of the time it's alright, but some code checks file permissions occasionally (esp. execute permission) and behaves unexpectedly when the permissions set in st_mode are in fact lower than the actual permissions for the file.

E.g. excerpt from kpathsea:

      if (stat (name, &s) == 0 && s.st_mode & (S_IXUSR|S_IXGRP|S_IXOTH)
                               /* Do not stop at directories. */
                               && !S_ISDIR(s.st_mode))
        self = name;
      else
        free (name);
sunfishcode commented 4 years ago

WASI recently added a way to set permissions on a file; we should consider adding a simple way to retrieve the permissions on a file too, which would allow us to implement this.

corwin-of-amber commented 3 years ago

I just came across this bug again :D is there any way to do this now?

Looks like stat_impl.h has to be modified to support it: https://github.com/WebAssembly/wasi-libc/blob/659ff414560721b1660a19685110e484a081c3d4/libc-bottom-half/cloudlibc/src/libc/sys/stat/stat_impl.h

sunfishcode commented 3 years ago

This needs WASI support first, and then we can add libc support for it. WASI has been focused on lower-level areas of the design lately, so we haven't had a chance to add this yet.

One question here is: what should implementations on Windows put in this field?