From 1f0b39eab5b8f08521a8be2b6f2b4b17f9e01b5c Mon Sep 17 00:00:00 2001 From: Alessandro Arzilli Date: Tue, 8 Feb 2022 19:53:45 +0100 Subject: [PATCH] proc: fix crash trying to open separate debug info (#2901) If debugInfoDirectories is set, the executable does not have debug info and build-id is not set we should not crash. --- pkg/proc/bininfo.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pkg/proc/bininfo.go b/pkg/proc/bininfo.go index 382c7282..d71b01c3 100644 --- a/pkg/proc/bininfo.go +++ b/pkg/proc/bininfo.go @@ -1209,7 +1209,7 @@ func (bi *BinaryInfo) openSeparateDebugInfo(image *Image, exe *elf.File, debugIn var err error for _, dir := range debugInfoDirectories { var potentialDebugFilePath string - if strings.Contains(dir, "build-id") { + if strings.Contains(dir, "build-id") && len(bi.BuildID) > 2 { potentialDebugFilePath = fmt.Sprintf("%s/%s/%s.debug", dir, bi.BuildID[:2], bi.BuildID[2:]) } else if strings.HasPrefix(image.Path, "/proc") { path, err := filepath.EvalSymlinks(image.Path)