Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions src/lib/libsyscall.js
Original file line number Diff line number Diff line change
Expand Up @@ -930,14 +930,15 @@ var SyscallsLibrary = {
__syscall_faccessat: (dirfd, path, amode, flags) => {
path = SYSCALLS.getStr(path);
#if ASSERTIONS
assert(!flags || flags == {{{ cDefs.AT_EACCESS }}});
assert(!(flags & ~({{{ cDefs.AT_EACCESS }}} | {{{ cDefs.AT_SYMLINK_NOFOLLOW }}})));
#endif
path = SYSCALLS.calculateAt(dirfd, path);
if (amode & ~{{{ cDefs.S_IRWXO }}}) {
// need a valid mode
return -{{{ cDefs.EINVAL }}};
}
var lookup = FS.lookupPath(path, { follow: true });
var nofollow = !!(flags & {{{ cDefs.AT_SYMLINK_NOFOLLOW }}});
var lookup = FS.lookupPath(path, { follow: !nofollow });
var node = lookup.node;
if (!node) {
return -{{{ cDefs.ENOENT }}};
Expand Down
22 changes: 22 additions & 0 deletions test/unistd/access.c
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,27 @@ void test_lchmod() {
#endif
}

void test_symlink_nofollow() {
#if defined(MEMFS)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this because windows does not support symlinks?

I wonder if this would be controlled instead via a separate "-DNO_SYMLINKS" compile flag that we set if and only if we are running on windows and using rawfs?

FILE* f = fopen("target_file", "w");
fclose(f);
symlink("target_file", "test_symlink");
symlink("dangling_target", "dangling_symlink");

// With AT_SYMLINK_NOFOLLOW, faccessat checks the symlink itself, not the target
assert(faccessat(AT_FDCWD, "test_symlink", F_OK, AT_SYMLINK_NOFOLLOW) == 0);

// Dangling symlink should still be found with AT_SYMLINK_NOFOLLOW (symlink exists)
assert(faccessat(AT_FDCWD, "dangling_symlink", F_OK, AT_SYMLINK_NOFOLLOW) == 0);

// Without AT_SYMLINK_NOFOLLOW, dangling symlink should fail
assert(faccessat(AT_FDCWD, "dangling_symlink", F_OK, 0) != 0);

// Combined flags should work
assert(faccessat(AT_FDCWD, "test_symlink", F_OK, AT_EACCESS | AT_SYMLINK_NOFOLLOW) == 0);
#endif
}

void test_chmod_errors() {
EM_ASM(
var ex;
Expand Down Expand Up @@ -119,6 +140,7 @@ int main() {
test_rename();
test_fchmod();
test_lchmod();
test_symlink_nofollow();
test_chmod_errors();

return 0;
Expand Down
Loading