1
0
mirror of https://github.com/golang/go synced 2024-11-17 16:54:44 -07:00

cmd/go: fix reading PT_NOTE segment with multiple notes

The old code was assuming that a PT_NOTE segment never had more than one
note, but there is no such requirement.

Fixes #13364.

Change-Id: I3f6b3716130bf7af6abe81b8e10571a8c7cd943c
Reviewed-on: https://go-review.googlesource.com/17331
Run-TryBot: Ian Lance Taylor <iant@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
Reviewed-by: Russ Cox <rsc@golang.org>
This commit is contained in:
Ian Lance Taylor 2015-12-01 21:16:29 -08:00
parent 0ea1c1f671
commit b64b3a7713
2 changed files with 19 additions and 11 deletions

View File

@ -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.

View File

@ -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") }`)