-
Notifications
You must be signed in to change notification settings - Fork 3.4k
[nodefs] Don't try to resolve absolute symlinks outside of the VFS #21805
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
Changes from all commits
Commits
Show all changes
24 commits
Select commit
Hold shift + click to select a range
a5fe8cd
readlink method returns grand parent when parent path equals current …
mho22 7d672ac
Merge branch 'emscripten-core:main' into patch-1
mho22 5941467
Improved readlink behavior to accept absolute paths
ca48b26
Improved readlink behavior to accept absolute paths
a39210b
Improved readlink behavior to understand absolute paths
521a95e
Merge branch 'main' into patch-1
mho22 122ff6a
Merge branch 'main' into patch-1
mho22 26a514a
Merge branch 'main' into patch-1
mho22 5300efc
Merge branch 'main' into patch-1
mho22 38c0631
Cleared readlink relative path manipulation
mho22 5abe4b7
Merge branch 'patch-1' of github.com:mho22/emscripten into patch-1
mho22 fdf4a4c
Improved readlink behavior to understand absolute paths
mho22 bd746f1
Improved readlink behavior to understand absolute paths
mho22 94b6d6d
Improved readlink behavior to understand absolute paths
mho22 8eefae8
Improved readlink behavior to understand absolute paths
mho22 d51fe58
Revert resolving outside VFS absolute symlinks
mho22 445b52a
Revert resolving outside VFS absolute symlinks
mho22 271c523
Revert resolving outside VFS absolute symlinks
mho22 82298ce
Revert resolving outside VFS absolute symlinks
mho22 a340985
Revert resolving outside VFS absolute symlinks
mho22 faaa6f7
Revert resolving outside VFS absolute symlinks
mho22 4a81b4b
Merge branch 'main' into patch-1
mho22 0ef6e4f
Revert resolving outside VFS absolute symlinks
mho22 bf23b63
Merge branch 'patch-1' of github.com:mho22/emscripten into patch-1
mho22 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,18 +1,26 @@ | ||
readlink(link) | ||
readlink: 'link' | ||
errno: No error information | ||
|
||
readlink(file) | ||
readlink: 'file' | ||
errno: Invalid argument | ||
not a link | ||
|
||
readlink(folder) | ||
readlink: 'directory' | ||
errno: Invalid argument | ||
not a link | ||
|
||
symlink/overwrite | ||
symlink: '/working/directory/relative' | ||
buffer: 'Relative' | ||
|
||
symlink/normal | ||
symlink: '/working/directory/subdirectory/subrelative' | ||
buffer: 'Subrelative' | ||
|
||
readlink(created link) | ||
symlink: '/working/subdirectoryrelative' | ||
buffer: 'Subdirectory' | ||
|
||
readlink(short buffer) | ||
symlink: '/working/directory/absolute' | ||
buffer: 'Absolute' | ||
|
||
symlink: '/working/directory/subdirectory/subabsolute' | ||
buffer: 'Subabsolute' | ||
|
||
symlink: '/working/subdirectoryabsolute' | ||
buffer: 'Subdirectory' |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -17,37 +17,60 @@ | |
|
||
void setup() { | ||
EM_ASM( | ||
fs.mkdirSync('new-directory', '0777'); | ||
fs.writeFileSync('new-directory/test', 'Link it'); | ||
fs.symlinkSync(fs.realpathSync('new-directory'), 'symlink'); | ||
fs.mkdirSync('directory', '0777'); | ||
fs.writeFileSync('directory/test', 'Link it'); | ||
fs.symlinkSync('/working/directory', 'inside-symlink'); | ||
fs.symlinkSync(fs.realpathSync('directory'), 'outside-symlink'); | ||
|
||
FS.mkdir('working'); | ||
FS.mount(NODEFS, { root: '.' }, 'working'); | ||
|
||
FS.mkdir('direct-link'); | ||
FS.mount(NODEFS, { root: 'symlink' }, 'direct-link'); | ||
FS.mkdir('mount-link'); | ||
FS.mount(NODEFS, { root: 'inside-symlink' }, 'mount-link'); | ||
); | ||
} | ||
|
||
int main() { | ||
setup(); | ||
|
||
char buf[1024]; | ||
readlink("/working/symlink", buf, 1024); | ||
printf("readlink: %s\n", buf); | ||
|
||
FILE* fd = fopen("/working/symlink/test", "r"); | ||
void test_inside_symlink() | ||
{ | ||
char buf[256] = {0}; | ||
readlink("/working/inside-symlink", buf, 256); | ||
printf("readlink: '%s'\n", buf); | ||
FILE* fd = fopen("/working/inside-symlink/test", "r"); | ||
assert(fd); | ||
char buffer[8] = {0}; | ||
int rtn = fread(buffer, 1, 7, fd); | ||
assert(rtn == 7); | ||
printf("buffer is '%s'\n", buffer); | ||
printf("buffer: '%s'\n", buffer); | ||
fclose(fd); | ||
} | ||
|
||
// This should fail, since it resolves to ../new-directory which is not | ||
// mounted | ||
fd = fopen("/direct-link/test", "r"); | ||
void test_outside_symlink() | ||
{ | ||
// outside-symlink is link to an absolute path which is not part of the emscripten VFS | ||
// and so we should be able to open it. | ||
FILE* fd = fopen("/working/outside-symlink/test", "r"); | ||
assert(fd == NULL); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. On it. |
||
assert(errno == ENOENT); | ||
} | ||
|
||
void test_mount_link() | ||
{ | ||
char buf[256] = {0}; | ||
readlink("/mount-link", buf, 256); | ||
printf("\nreadlink: '%s'\n", buf); | ||
FILE* fd = fopen("/mount-link/test", "r"); | ||
assert(fd); | ||
char buffer[8] = {0}; | ||
int rtn = fread(buffer, 1, 7, fd); | ||
assert(rtn == 7); | ||
printf("buffer: '%s'\n", buffer); | ||
fclose(fd); | ||
} | ||
|
||
int main() { | ||
setup(); | ||
test_inside_symlink(); | ||
test_outside_symlink(); | ||
test_mount_link(); | ||
return 0; | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,5 @@ | ||
readlink: /working/new-directory | ||
buffer is 'Link it' | ||
readlink: '/working/directory' | ||
buffer: 'Link it' | ||
|
||
readlink: '/working/directory' | ||
buffer: 'Link it' |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe add a comment here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
On it.