Skip to content

Commit

Permalink
cmd/go: fix reading PT_NOTE segment with multiple notes
Browse files Browse the repository at this point in the history
The old code was assuming that a PT_NOTE segment never had more than one
note, but there is no such requirement.

Fixes golang#13364.

Change-Id: I3f6b3716130bf7af6abe81b8e10571a8c7cd943c
Reviewed-on: https://go-review.googlesource.com/17331
Run-TryBot: Ian Lance Taylor <[email protected]>
TryBot-Result: Gobot Gobot <[email protected]>
Reviewed-by: Brad Fitzpatrick <[email protected]>
Reviewed-by: Russ Cox <[email protected]>
  • Loading branch information
ianlancetaylor committed Dec 2, 2015
1 parent 0ea1c1f commit b64b3a7
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 11 deletions.
27 changes: 19 additions & 8 deletions src/cmd/go/note.go
Original file line number Diff line number Diff line change
Expand Up @@ -121,15 +121,26 @@ func readELFGoBuildID(filename string, f *os.File, data []byte) (buildid string,
return "", err
}
}
nameSize := ef.ByteOrder.Uint32(note)
valSize := ef.ByteOrder.Uint32(note[4:])
tag := ef.ByteOrder.Uint32(note[8:])
name := note[12:16]
if nameSize != 4 || 16+valSize > uint32(len(note)) || tag != elfGoBuildIDTag || !bytes.Equal(name, elfGoNote) {
continue
}

return string(note[16 : 16+valSize]), nil
filesz := p.Filesz
for filesz >= 16 {
nameSize := ef.ByteOrder.Uint32(note)
valSize := ef.ByteOrder.Uint32(note[4:])
tag := ef.ByteOrder.Uint32(note[8:])
name := note[12:16]
if nameSize == 4 && 16+valSize <= uint32(len(note)) && tag == elfGoBuildIDTag && bytes.Equal(name, elfGoNote) {
return string(note[16 : 16+valSize]), nil
}

nameSize = (nameSize + 3) &^ 3
valSize = (valSize + 3) &^ 3
notesz := uint64(12 + nameSize + valSize)
if filesz <= notesz {
break
}
filesz -= notesz
note = note[notesz:]
}
}

// No note. Treat as successful but build ID empty.
Expand Down
3 changes: 0 additions & 3 deletions src/cmd/go/note_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,6 @@ func TestNoteReading2K(t *testing.T) {
}

func testNoteReading(t *testing.T) {
if runtime.GOOS == "dragonfly" {
t.Skipf("TestNoteReading is broken on dragonfly - golang.org/issue/13364", runtime.GOOS)
}
tg := testgo(t)
defer tg.cleanup()
tg.tempFile("hello.go", `package main; func main() { print("hello, world\n") }`)
Expand Down

0 comments on commit b64b3a7

Please sign in to comment.