]> Cypherpunks repositories - gostls13.git/commitdiff
debug/dwarf: better error handling in SeekPC
authorThan McIntosh <thanm@google.com>
Thu, 31 Mar 2022 11:47:19 +0000 (07:47 -0400)
committerThan McIntosh <thanm@google.com>
Fri, 1 Apr 2022 14:08:14 +0000 (14:08 +0000)
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>

src/debug/dwarf/entry.go
src/debug/dwarf/entry_test.go

index 3bc6a5454e379923c94ff0e2a93341c5638c3069..98c17dc08ac1bb5b9f4704c784afde6a342595ba 100644 (file)
@@ -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)
index 393ad89f522bc6f46ad85aa90227bf29476910cb..4e96dbfc1d56409ff49691dd6ab5423d7fe29150 100644 (file)
@@ -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")
+       }
+}