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.
This commit is contained in:
Alessandro Arzilli 2022-02-08 19:53:45 +01:00 committed by GitHub
parent 3829f4e06d
commit 1f0b39eab5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -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)