diff options
| author | Than McIntosh <thanm@google.com> | 2022-03-31 07:47:19 -0400 |
|---|---|---|
| committer | Than McIntosh <thanm@google.com> | 2022-04-01 14:08:14 +0000 |
| commit | 1fc3346275d0457cfc154b1001b25bd0cb0c1751 (patch) | |
| tree | 1d642c639508681710cddb3e9fb7b0b0c60e4b86 /src/debug | |
| parent | 2e8dc8f4725c84d352b718620628a4fb0f86e748 (diff) | |
| download | go-1fc3346275d0457cfc154b1001b25bd0cb0c1751.tar.xz | |
debug/dwarf: better error handling in SeekPC
The dwarf.Reader "SeekPC" method was not properly handling the case
of a truncated/empty unit (something that has header information
but an empty abbrev table and no DIEs). Add some guards to handle
this case.
Fixes #52045.
Change-Id: I978163eca3b610f7528058693b840931e90d3f63
Reviewed-on: https://go-review.googlesource.com/c/go/+/397054
Reviewed-by: Ian Lance Taylor <iant@golang.org>
Trust: Than McIntosh <thanm@google.com>
Run-TryBot: Than McIntosh <thanm@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Diffstat (limited to 'src/debug')
| -rw-r--r-- | src/debug/dwarf/entry.go | 2 | ||||
| -rw-r--r-- | src/debug/dwarf/entry_test.go | 15 |
2 files changed, 16 insertions, 1 deletions
diff --git a/src/debug/dwarf/entry.go b/src/debug/dwarf/entry.go index 3bc6a5454e..98c17dc08a 100644 --- a/src/debug/dwarf/entry.go +++ b/src/debug/dwarf/entry.go @@ -974,7 +974,7 @@ func (r *Reader) SeekPC(pc uint64) (*Entry, error) { u := &r.d.unit[unit] r.b = makeBuf(r.d, u, "info", u.off, u.data) e, err := r.Next() - if err != nil { + if err != nil || e == nil || e.Tag == 0 { return nil, err } ranges, err := r.d.Ranges(e) diff --git a/src/debug/dwarf/entry_test.go b/src/debug/dwarf/entry_test.go index 393ad89f52..4e96dbfc1d 100644 --- a/src/debug/dwarf/entry_test.go +++ b/src/debug/dwarf/entry_test.go @@ -427,3 +427,18 @@ func TestIssue51758(t *testing.T) { } } } + +func TestIssue52045(t *testing.T) { + var abbrev, aranges, frame, line, pubnames, ranges, str []byte + info := []byte{0x7, 0x0, 0x0, 0x0, 0x2, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0} + + // A hand-crafted input corresponding to a minimal-size + // .debug_info (header only, no DIEs) and an empty abbrev table. + data0, _ := New(abbrev, aranges, frame, info, line, pubnames, ranges, str) + reader0 := data0.Reader() + entry0, _ := reader0.SeekPC(0x0) + // main goal is to make sure we can get here without crashing + if entry0 != nil { + t.Errorf("got non-nil entry0, wanted nil") + } +} |
