Skip to content

Commit

Permalink
internal/buildinfo: avoid panic on nil symbol for elf
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
zpavlinovic committed May 15, 2024
1 parent 052eac7 commit 4a8a6ff
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion internal/buildinfo/additions_buildinfo.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ var ErrNoSymbols = errors.New("no symbol section")
// SymbolInfo is derived from cmd/internal/objfile/elf.go:symbols, symbolData.
func (x *elfExe) SymbolInfo(name string) (uint64, uint64, io.ReaderAt, error) {
sym, err := x.lookupSymbol(name)
if err != nil {
if err != nil || sym == nil {
if errors.Is(err, elf.ErrNoSymbols) {
return 0, 0, nil, ErrNoSymbols
}
Expand Down

0 comments on commit 4a8a6ff

Please sign in to comment.