Skip to content

[FS] lookupPath should throw an error on an empty string #23366

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

Merged
merged 6 commits into from
Jan 13, 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
7 changes: 3 additions & 4 deletions src/library_fs.js
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,9 @@ FS.staticInit();
// paths
//
lookupPath(path, opts = {}) {
if (!path) return { path: '', node: null };
if (!path) {
throw new FS.ErrnoError({{{ cDefs.ENOENT }}});
}
opts.follow_mount ??= true

if (!PATH.isAbs(path)) {
Expand Down Expand Up @@ -952,9 +954,6 @@ FS.staticInit();
stat(path, dontFollow) {
var lookup = FS.lookupPath(path, { follow: !dontFollow });
var node = lookup.node;
if (!node) {
throw new FS.ErrnoError({{{ cDefs.ENOENT }}});
}
var getattr = FS.checkOpExists(node.node_ops.getattr, {{{ cDefs.EPERM }}});
return getattr(node);
},
Expand Down
2 changes: 1 addition & 1 deletion test/other/codesize/test_codesize_cxx_ctors1.gzsize
Original file line number Diff line number Diff line change
@@ -1 +1 @@
8350
8343
2 changes: 1 addition & 1 deletion test/other/codesize/test_codesize_cxx_ctors1.jssize
Original file line number Diff line number Diff line change
@@ -1 +1 @@
20283
20273
2 changes: 1 addition & 1 deletion test/other/codesize/test_codesize_cxx_ctors2.gzsize
Original file line number Diff line number Diff line change
@@ -1 +1 @@
8332
8327
2 changes: 1 addition & 1 deletion test/other/codesize/test_codesize_cxx_ctors2.jssize
Original file line number Diff line number Diff line change
@@ -1 +1 @@
20251
20241
2 changes: 1 addition & 1 deletion test/other/codesize/test_codesize_cxx_except.gzsize
Original file line number Diff line number Diff line change
@@ -1 +1 @@
9349
9343
2 changes: 1 addition & 1 deletion test/other/codesize/test_codesize_cxx_except.jssize
Original file line number Diff line number Diff line change
@@ -1 +1 @@
24051
24041
2 changes: 1 addition & 1 deletion test/other/codesize/test_codesize_cxx_except_wasm.gzsize
Original file line number Diff line number Diff line change
@@ -1 +1 @@
8298
8294
2 changes: 1 addition & 1 deletion test/other/codesize/test_codesize_cxx_except_wasm.jssize
Original file line number Diff line number Diff line change
@@ -1 +1 @@
20176
20166
Original file line number Diff line number Diff line change
@@ -1 +1 @@
8298
8294
Original file line number Diff line number Diff line change
@@ -1 +1 @@
20176
20166
2 changes: 1 addition & 1 deletion test/other/codesize/test_codesize_cxx_lto.gzsize
Original file line number Diff line number Diff line change
@@ -1 +1 @@
8362
8357
2 changes: 1 addition & 1 deletion test/other/codesize/test_codesize_cxx_lto.jssize
Original file line number Diff line number Diff line change
@@ -1 +1 @@
20358
20348
2 changes: 1 addition & 1 deletion test/other/codesize/test_codesize_cxx_mangle.gzsize
Original file line number Diff line number Diff line change
@@ -1 +1 @@
9355
9349
2 changes: 1 addition & 1 deletion test/other/codesize/test_codesize_cxx_mangle.jssize
Original file line number Diff line number Diff line change
@@ -1 +1 @@
24051
24041
2 changes: 1 addition & 1 deletion test/other/codesize/test_codesize_cxx_noexcept.gzsize
Original file line number Diff line number Diff line change
@@ -1 +1 @@
8350
8343
2 changes: 1 addition & 1 deletion test/other/codesize/test_codesize_cxx_noexcept.jssize
Original file line number Diff line number Diff line change
@@ -1 +1 @@
20283
20273
2 changes: 1 addition & 1 deletion test/other/codesize/test_codesize_files_js_fs.gzsize
Original file line number Diff line number Diff line change
@@ -1 +1 @@
7653
7647
2 changes: 1 addition & 1 deletion test/other/codesize/test_codesize_files_js_fs.jssize
Original file line number Diff line number Diff line change
@@ -1 +1 @@
18830
18820
7 changes: 7 additions & 0 deletions test/stat/test_chmod.c
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,13 @@ void test() {
assert(s.st_mode == (S_IRUSR | S_IFREG));
#endif // WASMFS

assert(stat("", &s) == -1);
assert(errno == ENOENT);
assert(chmod("", 0777) == -1);
assert(errno == ENOENT);
assert(chown("", 1000, 1000) == -1);
assert(errno == ENOENT);

puts("success");
}

Expand Down
2 changes: 2 additions & 0 deletions test/stat/test_mknod.c
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,8 @@ void test() {
assert(S_ISCHR(s.st_mode));
#endif // WASMFS

assert(mknod("", 0777, 0) == -1);
assert(errno == ENOENT);
#endif

//
Expand Down
2 changes: 2 additions & 0 deletions test/test_other.py
Original file line number Diff line number Diff line change
Expand Up @@ -13743,6 +13743,8 @@ def test_unistd_sleep(self):

@also_with_wasmfs
def test_unistd_fstatfs(self):
if not self.get_setting('WASMFS'):
self.skipTest("fstatfs is broken in js fs, will be fixed in PR #23381")
self.do_run_in_out_file_test('unistd/fstatfs.c')

@no_windows("test is Linux-specific")
Expand Down
4 changes: 4 additions & 0 deletions test/unistd/truncate.c
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,10 @@ int main() {
errno = 0;
printf("\n");

printf("truncate(empty_path, 2): %d\n", truncate("", 2));
printf("errno: %s\n", strerror(errno));
printf("\n");

printf("ftruncate(readonly, 4): %d\n", ftruncate(f2, 4));
printf("errno: %s\n", strerror(errno));
fstat(f2, &s);
Expand Down
3 changes: 3 additions & 0 deletions test/unistd/truncate.out
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,9 @@ truncate(readonly, 2): -1
errno: Permission denied
st_size: 6

truncate(empty_path, 2): -1
errno: No such file or directory

ftruncate(readonly, 4): -1
errno: Invalid argument
st_size: 6
Expand Down
5 changes: 5 additions & 0 deletions test/utime/test_futimens.c
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,11 @@ void test() {

close(fd);

// TODO:
// printf("check utime on empty path...\n");
// assert(utime("", &tb) == -1);
// assert(errno == ENOENT);

puts("success");
}

Expand Down
Loading