Skip to content

Commit

Permalink
Do not double-prefix symlink paths with base directory
Browse files Browse the repository at this point in the history
Fixes #1950

Co-authored-by: Joseph Palermo <jpalermo@vmware.com>
Signed-off-by: Joseph Palermo <jpalermo@vmware.com>
Signed-off-by: Chris Selzo <cselzo@vmware.com>
Co-authored-by: Chris Selzo <cselzo@vmware.com>
  • Loading branch information
selzoc and jpalermo committed Aug 22, 2023
1 parent ee121cf commit e663f35
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions syft/internal/fileresolver/directory_indexer.go
Original file line number Diff line number Diff line change
Expand Up @@ -349,9 +349,13 @@ func (r directoryIndexer) addSymlinkToIndex(p string, info os.FileInfo) (string,
}

if filepath.IsAbs(linkTarget) {
linkTarget = filepath.Clean(linkTarget)
// if the link is absolute (e.g, /bin/ls -> /bin/busybox) we need to
// resolve relative to the root of the base directory
linkTarget = filepath.Join(r.base, filepath.Clean(linkTarget))
// resolve relative to the root of the base directory, if it is not already
// prefixed with the base directory
if !strings.HasPrefix(linkTarget, r.base) {
linkTarget = filepath.Join(r.base, filepath.Clean(linkTarget))
}
} else {
// if the link is not absolute (e.g, /dev/stderr -> fd/2 ) we need to
// resolve it relative to the directory in question (e.g. resolve to
Expand Down

0 comments on commit e663f35

Please sign in to comment.