Skip to content

Commit 675698d

Browse files
authored
Raise ENOSYS if AT_SYMLINK_NOFOLLOW is used with chmod or chown in nodefs (#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.
1 parent 0585506 commit 675698d

File tree

4 files changed

+19
-5
lines changed

4 files changed

+19
-5
lines changed

src/library_fs.js

+4-2
Original file line numberDiff line numberDiff line change
@@ -972,7 +972,8 @@ FS.staticInit();
972972
}
973973
node.node_ops.setattr(node, {
974974
mode: (mode & {{{ cDefs.S_IALLUGO }}}) | (node.mode & ~{{{ cDefs.S_IALLUGO }}}),
975-
ctime: Date.now()
975+
ctime: Date.now(),
976+
dontFollow
976977
});
977978
},
978979
lchmod(path, mode) {
@@ -994,7 +995,8 @@ FS.staticInit();
994995
throw new FS.ErrnoError({{{ cDefs.EPERM }}});
995996
}
996997
node.node_ops.setattr(node, {
997-
timestamp: Date.now()
998+
timestamp: Date.now(),
999+
dontFollow
9981000
// we ignore the uid / gid for now
9991001
});
10001002
},

src/library_nodefs.js

+3
Original file line numberDiff line numberDiff line change
@@ -156,6 +156,9 @@ addToLibrary({
156156
var path = NODEFS.realPath(node);
157157
NODEFS.tryFSOperation(() => {
158158
if (attr.mode !== undefined) {
159+
if (attr.dontFollow) {
160+
throw new FS.ErrnoError({{{ cDefs.ENOSYS }}});
161+
}
159162
var mode = attr.mode;
160163
if (NODEFS.isWindows) {
161164
// Windows only supports S_IREAD / S_IWRITE (S_IRUSR / S_IWUSR)

test/stat/test_chmod.c

+9
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,15 @@ void test() {
9393
err = fchmodat(AT_FDCWD, "otherfile", S_IXUSR, 0);
9494
assert(!err);
9595

96+
assert(symlink("otherfile", "link") == 0);
97+
err = fchmodat(AT_FDCWD, "link", S_IXGRP, AT_SYMLINK_NOFOLLOW);
98+
#if defined(NODEFS) || defined(NODERAWFS)
99+
assert(err == -1);
100+
assert(errno == ENOTSUP);
101+
#else
102+
assert(err == 0);
103+
#endif
104+
96105
memset(&s, 0, sizeof s);
97106
stat("otherfile", &s);
98107
assert(s.st_mode == (S_IXUSR | S_IFREG));

test/test_core.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -5524,10 +5524,10 @@ def test_fstatat(self):
55245524
self.do_runf('stat/test_fstatat.c', 'success')
55255525

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

0 commit comments

Comments
 (0)