Skip to content

Fix path resolution for symlinks #23072

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 8 commits into from
Dec 6, 2024

Conversation

hoodmane
Copy link
Collaborator

@hoodmane hoodmane commented Dec 4, 2024

If /a/link is a symlink to directory /b/c then /a/link/.. should be resolved to /b/c/.. which is /b. Currently, we cancel out link/.. to get /a. The problem is that we apply PATH_FS.resolve and PATH_FS.normalize to paths. These functions cancel .. incorrectly.

This at least partially handles the situation. lookupPath is modified to avoid calls that call PATH_FS.normalize(). We check that mkdir, open, stat, truncate, and chmod now work correctly.

If `/a/link` is a symlink to directory `/b/c` then `/a/link/..` should be
resolved to `/b/c/..` which is `/b`. Currently, we cancel out `link/..` to get
`/a`. The problem is that we apply `PATH_FS.resolve` and `PATH_FS.normalize` to
paths. These functions cancel `..` incorrectly.

This at least partially handles the situation. `lookupPath` is modified to avoid
calls that call `PATH_FS.normalize()`. We check that `mkdir`, `open`, and
`stat` now work correctly.
if (!dir.endsWith("/")) {
dir += "/"
}
return dir + path;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How is this different to the old code?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

join2 calls normalize which will incorrectly replace /a/b/.. with /a.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How about just return dir + '/' + path ? Or return '${dir}/${path}'?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That'll probably work fine, I put it in and will let the CI say.

@sbc100 sbc100 merged commit e16230e into emscripten-core:main Dec 6, 2024
26 of 28 checks passed
dschuff added a commit to dschuff/emscripten that referenced this pull request Dec 6, 2024
dschuff added a commit that referenced this pull request Dec 6, 2024
hedwigz pushed a commit to hedwigz/emscripten that referenced this pull request Dec 18, 2024
If `/a/link` is a symlink to directory `/b/c` then `/a/link/..` should
be resolved to `/b/c/..` which is `/b`. Currently, we cancel out
`link/..` to get `/a`. The problem is that we apply `PATH_FS.resolve`
and `PATH_FS.normalize` to paths. These functions cancel `..`
incorrectly.

This at least partially handles the situation. `lookupPath` is modified
to avoid calls that call `PATH_FS.normalize()`. We check that `mkdir`,
`open`, `stat`, `truncate`, and `chmod` now work correctly.
hedwigz pushed a commit to hedwigz/emscripten that referenced this pull request Dec 18, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants