Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Raise ENOSYS if AT_SYMLINK_NOFOLLOW is used with chmod or chown in nodefs #23307

Merged
merged 3 commits into from
Jan 9, 2025
Merged
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
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
Loading