From 14bcebd8b7e2527dc9debab91d76e314f59dd037 Mon Sep 17 00:00:00 2001 From: Evan Lezar Date: Tue, 31 Jan 2023 12:43:58 +0100 Subject: [PATCH] Fix relative link resolution for ldcache Signed-off-by: Evan Lezar --- internal/ldcache/ldcache.go | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/internal/ldcache/ldcache.go b/internal/ldcache/ldcache.go index eefaad2f..5ea1d527 100644 --- a/internal/ldcache/ldcache.go +++ b/internal/ldcache/ldcache.go @@ -302,11 +302,14 @@ func (c *ldcache) resolve(target string) (string, error) { 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) + // We return absolute paths for all targets + if !filepath.IsAbs(link) || strings.HasPrefix(link, ".") { + link = filepath.Join(filepath.Dir(target), link) } + // Ensure that the returned path is relative to the root. + link = filepath.Join(c.root, link) + c.logger.Debugf("Resolved link: '%v' => '%v'", name, link) return link, nil }