-
Notifications
You must be signed in to change notification settings - Fork 18k
path/filepath: does not work at all for paths containing symbolic links on directories #23444
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
Comments
This bug would be much clearer if you provided a small, self-contained program showing the unexpected output, and stating what output you were expecting. Please try to provide one. |
My bet is on working as intended. |
An example for misbehaving EvalSymlinks could be: Just use this small program (
on the following filesystem structure:
by calling Expected result is obviously |
Another example for
The file Therefore all those functions cannot be used on paths given by somebody else (i.e. Input Parameter), because the result might be not as expected, if there are |
Deleted by me, wrong setup used. Will try again. |
I guess that the following patch fix the problem. diff --git a/src/path/filepath/symlink.go b/src/path/filepath/symlink.go
index 824aee4e49..9e0af00c73 100644
--- a/src/path/filepath/symlink.go
+++ b/src/path/filepath/symlink.go
@@ -74,6 +74,16 @@ func walkLinks(path string, linksWalked *int) (string, error) {
if err != nil {
return "", err
}
+ for {
+ var islink bool
+ newdir, islink, err = walkLink(newdir, linksWalked)
+ if err != nil {
+ return "", err
+ }
+ if !islink {
+ break
+ }
+ }
newpath, islink, err := walkLink(Join(newdir, file), linksWalked)
if err != nil {
return "", err |
The intended use is to first resolve symlinks and only then use Join or any other function documented to work only lexically. |
After properly reproducing the setup, I can reproduce your error result, that's all I know ATM. |
FYI, the problem is coming from wrong evaluation order. |
Its not what I would call the wrong evaluation order but more Cleaning at every possible step. The only safe time to Clean is when we are done since Join and Clean does not lstat before eliding dots. |
While I like the approach above, it doesn't quite work in all situations. I have added a single test case which highlights the problem. The above code only solves 1 out of 3 scenarios performed in the tests. |
Change https://golang.org/cl/121305 mentions this issue: |
Change https://golang.org/cl/121497 mentions this issue: |
Change https://golang.org/cl/121676 mentions this issue: |
which version go fixed this bug? |
7d27e87 change has not been released yet. It will be part of go1.12. Alex |
What version of Go are you using (
go version
)?all /up to 1.10
Does this issue reproduce with the latest release?
yes
What operating system and processor architecture are you using (
go env
)?all
What did you do?
Using
filepath.Join
orfilepath.EvalSymlinks
What did you expect to see?
I expected those functions to transform valid file paths to still valid file paths
What did you see instead?
Completely corrupted file paths if the path contains a symbolic link to a directory
General Description
The first time I observed a strange behaviour was by using terraform. terrform switched to the
use of
filepath.EvalSymlinks
. Afterwards my terraform project using symbolic links was completely corrupted. Later I wanted to use this function in my own coding, with the same strange results.An analysis of the filepath package yields something I couldn't believe:
The package defines a function
Clean
that formally normalizes a file path by eliminating..
and.
entries. As described in the documentation this is done WITHOUT observing the actual file system. Although this is no problem for the function itself, because it is designed to do so, it becomes a severe problem for the whole package, because NEARLY ALL functions internally useClean
to clean the path even on intermediate results. As a consequence even functions likeJoin
may deliver corrupted invalid results for valid inputs if the path incorporates symbolic links to directories. EspeciallyEvalSymlinks
cannot be used to evaluate paths to existing files, becauseClean
is internally used to normalize content of symbolic links.Therefore I had to switch to a modified implementation solving this problem.
The text was updated successfully, but these errors were encountered: