Skip to content

Commit

Permalink
Raise ENOSYS if AT_SYMLINK_NOFOLLOW is used with chmod or chown in no…
Browse files Browse the repository at this point in the history
…defs (#23307)

It cannot support this since node doesn't support it. So we should tell
the truth that we can't do it instead of ignoring it.
  • Loading branch information
hoodmane authored Jan 9, 2025
1 parent 0585506 commit 675698d
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 5 deletions.
6 changes: 4 additions & 2 deletions src/library_fs.js
Original file line number Diff line number Diff line change
Expand Up @@ -972,7 +972,8 @@ FS.staticInit();
}
node.node_ops.setattr(node, {
mode: (mode & {{{ cDefs.S_IALLUGO }}}) | (node.mode & ~{{{ cDefs.S_IALLUGO }}}),
ctime: Date.now()
ctime: Date.now(),
dontFollow
});
},
lchmod(path, mode) {
Expand All @@ -994,7 +995,8 @@ FS.staticInit();
throw new FS.ErrnoError({{{ cDefs.EPERM }}});
}
node.node_ops.setattr(node, {
timestamp: Date.now()
timestamp: Date.now(),
dontFollow
// we ignore the uid / gid for now
});
},
Expand Down
3 changes: 3 additions & 0 deletions src/library_nodefs.js
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,9 @@ addToLibrary({
var path = NODEFS.realPath(node);
NODEFS.tryFSOperation(() => {
if (attr.mode !== undefined) {
if (attr.dontFollow) {
throw new FS.ErrnoError({{{ cDefs.ENOSYS }}});
}
var mode = attr.mode;
if (NODEFS.isWindows) {
// Windows only supports S_IREAD / S_IWRITE (S_IRUSR / S_IWUSR)
Expand Down
9 changes: 9 additions & 0 deletions test/stat/test_chmod.c
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,15 @@ void test() {
err = fchmodat(AT_FDCWD, "otherfile", S_IXUSR, 0);
assert(!err);

assert(symlink("otherfile", "link") == 0);
err = fchmodat(AT_FDCWD, "link", S_IXGRP, AT_SYMLINK_NOFOLLOW);
#if defined(NODEFS) || defined(NODERAWFS)
assert(err == -1);
assert(errno == ENOTSUP);
#else
assert(err == 0);
#endif

memset(&s, 0, sizeof s);
stat("otherfile", &s);
assert(s.st_mode == (S_IXUSR | S_IFREG));
Expand Down
6 changes: 3 additions & 3 deletions test/test_core.py
Original file line number Diff line number Diff line change
Expand Up @@ -5524,10 +5524,10 @@ def test_fstatat(self):
self.do_runf('stat/test_fstatat.c', 'success')

@crossplatform
@also_with_wasmfs
@also_with_noderawfs
@with_all_fs
def test_stat_chmod(self):
if self.get_setting('NODERAWFS') and WINDOWS:
nodefs = '-DNODEFS' in self.emcc_args or '-DNODERAWFS' in self.emcc_args
if nodefs and WINDOWS:
self.skipTest('mode bits work differently on windows')
if self.get_setting('WASMFS') and self.get_setting('NODERAWFS'):
self.skipTest('test requires symlink creation which currently missing from wasmfs+noderawfs')
Expand Down

0 comments on commit 675698d

Please sign in to comment.