Skip to content
Merged
Show file tree
Hide file tree
Changes from 6 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
8 changes: 7 additions & 1 deletion src/library_fs.js
Original file line number Diff line number Diff line change
Expand Up @@ -1083,7 +1083,10 @@ FS.staticInit();
}
} else {
// node doesn't exist, try to create it
node = FS.mknod(path, mode, 0);
// Ignore the permission bits here to ensure we can `open` this new
// file below. We use chmod below the apply the permissions once the
// file is open.
node = FS.mknod(path, mode | 0o777, 0);
created = true;
}
}
Expand Down Expand Up @@ -1133,6 +1136,9 @@ FS.staticInit();
if (stream.stream_ops.open) {
stream.stream_ops.open(stream);
}
if (created) {
FS.chmod(node, mode & 0o777);
}
#if expectToReceiveOnModule('logReadFiles')
if (Module['logReadFiles'] && !(flags & {{{ cDefs.O_WRONLY}}})) {
if (!(path in FS.readFiles)) {
Expand Down
19 changes: 19 additions & 0 deletions test/fs/test_fs_open_no_permissions.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
#include <stdio.h>
#include <unistd.h>
#include <assert.h>
#include <fcntl.h>
#include <string.h>
#include <sys/stat.h>
#include <assert.h>
#include <errno.h>
#include <string.h>

int main() {
int res = open("a", O_CREAT, 0);
printf("error: %s\n", strerror(errno));
assert(res >= 0);
struct stat st;
assert(stat("a", &st) == 0);
assert((st.st_mode & 0777) == 0);
printf("success\n");
}
4 changes: 4 additions & 0 deletions test/test_core.py
Original file line number Diff line number Diff line change
Expand Up @@ -5858,6 +5858,10 @@ def test_fs_rename_on_existing(self):
self.set_setting('FORCE_FILESYSTEM')
self.do_runf('fs/test_fs_rename_on_existing.c', 'success')

@also_with_nodefs_both
def test_fs_open_no_permissions(self):
self.do_runf('fs/test_fs_open_no_permissions.c', 'success')

@also_with_nodefs_both
def test_fs_mkdir_dotdot(self):
self.do_runf('fs/test_fs_mkdir_dotdot.c', 'success')
Expand Down
Loading