diff --git a/pkg/oci/containerize.go b/pkg/oci/containerize.go index feb9cf2fcf..25edfd08d3 100644 --- a/pkg/oci/containerize.go +++ b/pkg/oci/containerize.go @@ -211,7 +211,7 @@ func validateLink(root, path string, info os.FileInfo) error { } // Calculate the actual target of the link - // (relative to our current working directory) + // (relative to the parent of the symlink) lnkTgt := filepath.Join(filepath.Dir(path), tgt) // Calculate the relative path from the function's root to diff --git a/pkg/oci/containerize_test.go b/pkg/oci/containerize_test.go index 369d45fdd2..cd587b06d4 100644 --- a/pkg/oci/containerize_test.go +++ b/pkg/oci/containerize_test.go @@ -3,6 +3,7 @@ package oci import ( "os" "path/filepath" + "runtime" "testing" ) @@ -40,4 +41,18 @@ func Test_validateLink(t *testing.T) { } }) } + // Run a windows-specific absolute path test + // Note this technically succeeds on unix systems, but wrapping in + // an runtime check seems like a good idea to make it more clear. + if runtime.GOOS != "windows" { + path := "c://some/absolute/path" + info, err := os.Lstat(path) + if err != nil { + t.Fatal(err) + } + err = validateLink(root, path, info) + if err == nil { + t.Fatal("absolute path should be invalid on windows") + } + } }