Skip to content

Commit 4a8a6ff

Browse files
committed
internal/buildinfo: avoid panic on nil symbol for elf
For very old binaries or binaries built with forks of Go, looking up an elf symbol that does not exists might not return an error, yet just a nil symbol, resulting in a panic. We hence make an additional check. This is also consistent with other binary formats. Change-Id: I488eeca4ada27a0be48c7da82ca7b1391a7ce394 Reviewed-on: https://go-review.googlesource.com/c/vuln/+/585336 LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> TryBot-Result: Gopher Robot <gobot@golang.org> Reviewed-by: Ian Cottrell <iancottrell@google.com> Run-TryBot: Zvonimir Pavlinovic <zpavlinovic@google.com>
1 parent 052eac7 commit 4a8a6ff

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

internal/buildinfo/additions_buildinfo.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ var ErrNoSymbols = errors.New("no symbol section")
2626
// SymbolInfo is derived from cmd/internal/objfile/elf.go:symbols, symbolData.
2727
func (x *elfExe) SymbolInfo(name string) (uint64, uint64, io.ReaderAt, error) {
2828
sym, err := x.lookupSymbol(name)
29-
if err != nil {
29+
if err != nil || sym == nil {
3030
if errors.Is(err, elf.ErrNoSymbols) {
3131
return 0, 0, nil, ErrNoSymbols
3232
}

0 commit comments

Comments
 (0)