Commit b64b3a77 authored by Ian Lance Taylor's avatar Ian Lance Taylor

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: default avatarBrad Fitzpatrick <bradfitz@golang.org>
Reviewed-by: default avatarRuss Cox <rsc@golang.org>
parent 0ea1c1f6
...@@ -121,15 +121,26 @@ func readELFGoBuildID(filename string, f *os.File, data []byte) (buildid string, ...@@ -121,15 +121,26 @@ func readELFGoBuildID(filename string, f *os.File, data []byte) (buildid string,
return "", err 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. // No note. Treat as successful but build ID empty.
......
...@@ -28,9 +28,6 @@ func TestNoteReading2K(t *testing.T) { ...@@ -28,9 +28,6 @@ func TestNoteReading2K(t *testing.T) {
} }
func testNoteReading(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) tg := testgo(t)
defer tg.cleanup() defer tg.cleanup()
tg.tempFile("hello.go", `package main; func main() { print("hello, world\n") }`) tg.tempFile("hello.go", `package main; func main() { print("hello, world\n") }`)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment