Skip to content

Commit

Permalink
windows-specific absolute link check
Browse files Browse the repository at this point in the history
  • Loading branch information
lkingland committed Feb 16, 2024
1 parent bd66352 commit a7c8d1f
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
2 changes: 1 addition & 1 deletion pkg/oci/containerize.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
15 changes: 15 additions & 0 deletions pkg/oci/containerize_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package oci
import (
"os"
"path/filepath"
"runtime"
"testing"
)

Expand Down Expand Up @@ -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")
}
}
}

0 comments on commit a7c8d1f

Please sign in to comment.