Ensure root is included in absolute ldcache paths

Signed-off-by: Evan Lezar <elezar@nvidia.com>
This commit is contained in:
Evan Lezar 2022-12-13 14:34:53 +01:00
parent f350f0c0bb
commit ccd1961c60

View File

@ -289,13 +289,27 @@ func (c *ldcache) Lookup(libs ...string) (paths32, paths64 []string) {
func (c *ldcache) resolve(target string) (string, error) { func (c *ldcache) resolve(target string) (string, error) {
name := filepath.Join(c.root, target) name := filepath.Join(c.root, target)
c.logger.Debugf("checking %v", name) c.logger.Debugf("checking %v", string(name))
link, err := filepath.EvalSymlinks(name) info, err := os.Lstat(name)
if err != nil {
return "", fmt.Errorf("failed to get file info: %v", info)
}
if info.Mode()&os.ModeSymlink == 0 {
c.logger.Debugf("Resolved regular file: %v", name)
return name, nil
}
link, err := os.Readlink(name)
if err != nil { if err != nil {
return "", fmt.Errorf("failed to resolve symlink: %v", err) return "", fmt.Errorf("failed to resolve symlink: %v", err)
} }
if filepath.IsAbs(link) {
c.logger.Debugf("Found absolute link %v", link)
link = filepath.Join(c.root, link)
}
c.logger.Debugf("Resolved link: '%v' => '%v'", name, link) c.logger.Debugf("Resolved link: '%v' => '%v'", name, link)
return link, nil return link, nil
} }