Skip to content

Commit dd97871

Browse files
thanmgopherbot
authored andcommitted
debug/dwarf: better stmt list attr checking in LineReader
Check for insane statement list attribute values when constructing LineReader's for a compilation unit. Fixes #52354. Change-Id: Icb5298db31f6c5fe34c44e0ed4fe277a7cd676b9 Reviewed-on: https://go-review.googlesource.com/c/go/+/400255 Run-TryBot: Than McIntosh <[email protected]> Auto-Submit: Than McIntosh <[email protected]> TryBot-Result: Gopher Robot <[email protected]> Reviewed-by: Ian Lance Taylor <[email protected]>
1 parent 62b8ec7 commit dd97871

File tree

2 files changed

+30
-1
lines changed

2 files changed

+30
-1
lines changed

src/debug/dwarf/line.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,7 @@ func (d *Data) LineReader(cu *Entry) (*LineReader, error) {
152152
// cu has no line table.
153153
return nil, nil
154154
}
155-
if off > int64(len(d.line)) {
155+
if off < 0 || off > int64(len(d.line)) {
156156
return nil, errors.New("AttrStmtList value out of range")
157157
}
158158
// AttrCompDir is optional if all file names are absolute. Use

src/debug/dwarf/line_test.go

+29
Original file line numberDiff line numberDiff line change
@@ -389,3 +389,32 @@ func TestPathJoin(t *testing.T) {
389389
}
390390
}
391391
}
392+
393+
func TestPathLineReaderMalformed(t *testing.T) {
394+
// This test case drawn from issue #52354. What's happening
395+
// here is that the stmtList attribute in the compilation
396+
// unit is malformed (negative).
397+
var aranges, frame, pubnames, ranges, str []byte
398+
abbrev := []byte{0x10, 0x20, 0x20, 0x20, 0x21, 0x20, 0x10, 0x21, 0x61,
399+
0x0, 0x0, 0xff, 0x20, 0xff, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20,
400+
0x20, 0x20, 0x20, 0x20, 0x20, 0x20}
401+
info := []byte{0x0, 0x0, 0x0, 0x9, 0x0, 0x2, 0x0, 0x0, 0x0, 0x0,
402+
0x20, 0x10, 0x10}
403+
line := []byte{0x20}
404+
Data0, err := New(abbrev, aranges, frame, info, line, pubnames, ranges, str)
405+
if err != nil {
406+
t.Fatalf("error unexpected: %v", err)
407+
}
408+
Reader0 := Data0.Reader()
409+
Entry0, err := Reader0.Next()
410+
if err != nil {
411+
t.Fatalf("error unexpected: %v", err)
412+
}
413+
LineReader0, err := Data0.LineReader(Entry0)
414+
if err == nil {
415+
t.Fatalf("expected error")
416+
}
417+
if LineReader0 != nil {
418+
t.Fatalf("expected nil line reader")
419+
}
420+
}

0 commit comments

Comments
 (0)