From: Ian Lance Taylor Date: Wed, 2 Dec 2015 05:16:29 +0000 (-0800) Subject: cmd/go: fix reading PT_NOTE segment with multiple notes X-Git-Tag: go1.6beta1~238 X-Git-Url: http://www.git.cypherpunks.su/?a=commitdiff_plain;h=b64b3a771320d95a4c9b8456e8de0e70702a0275;p=gostls13.git 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 TryBot-Result: Gobot Gobot Reviewed-by: Brad Fitzpatrick Reviewed-by: Russ Cox --- diff --git a/src/cmd/go/note.go b/src/cmd/go/note.go index c7346a5731..f846eeb62b 100644 --- a/src/cmd/go/note.go +++ b/src/cmd/go/note.go @@ -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. diff --git a/src/cmd/go/note_test.go b/src/cmd/go/note_test.go index 0d43b9ec93..bfaa75f6c3 100644 --- a/src/cmd/go/note_test.go +++ b/src/cmd/go/note_test.go @@ -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") }`)