From 9fc82b9d78bd36822ac8169017d3cbe8f01304f8 Mon Sep 17 00:00:00 2001 From: Hood Chatham Date: Wed, 11 Dec 2024 16:37:57 +0100 Subject: [PATCH 1/3] Raise ENOSYS if AT_SYMLINK_NOFOLLOW is used with chmod or chown in nodefs --- src/library_fs.js | 6 ++++-- src/library_nodefs.js | 3 +++ test/stat/test_chmod.c | 9 +++++++++ test/test_core.py | 3 +-- 4 files changed, 17 insertions(+), 4 deletions(-) diff --git a/src/library_fs.js b/src/library_fs.js index 15da9944615b5..7ba5ebec5aa9f 100644 --- a/src/library_fs.js +++ b/src/library_fs.js @@ -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) { @@ -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 }); }, diff --git a/src/library_nodefs.js b/src/library_nodefs.js index bdbfbe6cab863..6615269ebd8f9 100644 --- a/src/library_nodefs.js +++ b/src/library_nodefs.js @@ -153,6 +153,9 @@ addToLibrary({ }; }, setattr(node, attr) { + if (attr.dontFollow) { + throw new FS.ErrnoError({{{ cDefs.ENOSYS }}}); + } var path = NODEFS.realPath(node); NODEFS.tryFSOperation(() => { if (attr.mode !== undefined) { diff --git a/test/stat/test_chmod.c b/test/stat/test_chmod.c index b9428255efdbf..261d247c32270 100644 --- a/test/stat/test_chmod.c +++ b/test/stat/test_chmod.c @@ -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)); diff --git a/test/test_core.py b/test/test_core.py index 642b9cc3150c4..deef915367a25 100644 --- a/test/test_core.py +++ b/test/test_core.py @@ -5524,8 +5524,7 @@ 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: self.skipTest('mode bits work differently on windows') From 4790a982f04f038b322b53ade478f18eb41143c5 Mon Sep 17 00:00:00 2001 From: Hood Chatham Date: Thu, 9 Jan 2025 16:28:33 +0100 Subject: [PATCH 2/3] Skip nodefs test in windows --- test/test_core.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/test/test_core.py b/test/test_core.py index deef915367a25..85b13c99c5e4d 100644 --- a/test/test_core.py +++ b/test/test_core.py @@ -5526,7 +5526,8 @@ def test_fstatat(self): @crossplatform @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') From f39ec172cfab24b2c995ef203135a8951144b5cc Mon Sep 17 00:00:00 2001 From: Hood Chatham Date: Thu, 9 Jan 2025 17:28:36 +0100 Subject: [PATCH 3/3] Only throw if we are doing a chmod with dontFollow, not for chown --- src/library_nodefs.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/library_nodefs.js b/src/library_nodefs.js index 6615269ebd8f9..b5d893f5a6355 100644 --- a/src/library_nodefs.js +++ b/src/library_nodefs.js @@ -153,12 +153,12 @@ addToLibrary({ }; }, setattr(node, attr) { - if (attr.dontFollow) { - throw new FS.ErrnoError({{{ cDefs.ENOSYS }}}); - } 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)