Skip to content
Merged
Show file tree
Hide file tree
Changes from 3 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: 5 additions & 2 deletions src/library_fs.js
Original file line number Diff line number Diff line change
Expand Up @@ -290,6 +290,9 @@ FS.staticInit();
if (errCode) {
throw new FS.ErrnoError(errCode);
}
if (name === "..") {
return parent.parent;
}
var hash = FS.hashName(parent.id, name);
#if CASE_INSENSITIVE_FS
name = name.toLowerCase();
Expand Down Expand Up @@ -664,8 +667,8 @@ FS.staticInit();
mknod(path, mode, dev) {
var lookup = FS.lookupPath(path, { parent: true });
var parent = lookup.node;
var name = PATH.basename(path);
if (!name || name === '.' || name === '..') {
var name = path.split('/').filter((p) => !!p && (p !== '.')).pop();
if (!name) {
throw new FS.ErrnoError({{{ cDefs.EINVAL }}});
}
var errCode = FS.mayCreate(parent, name);
Expand Down
44 changes: 44 additions & 0 deletions test/fs/test_fs_mkdir_dotdot.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
#include <sys/stat.h>
#include <sys/types.h>
#include <unistd.h>
#include <sys/stat.h>
#include <stdio.h>
#include <fcntl.h>
#include <errno.h>
#include <string.h>
#include <assert.h>
#if defined(__EMSCRIPTEN__)
#include <emscripten.h>
#endif

void makedir(const char *dir) {
int rtn = mkdir(dir, 0777);
assert(rtn == 0);
}

void changedir(const char *dir) {
int rtn = chdir(dir);
assert(rtn == 0);
}

void setup() {
#if defined(__EMSCRIPTEN__) && defined(NODEFS)
makedir("working");
EM_ASM(FS.mount(NODEFS, { root: '.' }, 'working'));
changedir("working");
#endif
}

int main() {
setup();
mkdir("test", 0777);
mkdir("test/a", 0777);
mkdir("test/a/..", 0777);
printf("error: %s\n", strerror(errno));
assert(errno == EEXIST);
mkdir("test/a/.", 0777);
printf("error: %s\n", strerror(errno));
assert(errno == EEXIST);
printf("success\n");
}

8 changes: 8 additions & 0 deletions test/test_core.py
Original file line number Diff line number Diff line change
Expand Up @@ -5900,6 +5900,14 @@ def test_fs_rename_on_existing(self, args):
self.set_setting('FORCE_FILESYSTEM')
self.do_runf('fs/test_fs_rename_on_existing.c', 'success', emcc_args=args)

@parameterized({
'': ([],),
'nodefs': (['-DNODEFS', '-lnodefs.js'],),
'noderawfs': (['-sNODERAWFS'],)
})
def test_fs_mkdir_dotdot(self, args):
self.do_runf('fs/test_fs_mkdir_dotdot.c', 'success', emcc_args=args)

def test_sigalrm(self):
self.do_runf('test_sigalrm.c', 'Received alarm!')
self.set_setting('EXIT_RUNTIME')
Expand Down
Loading