Skip to content

Commit b64b3a7

Browse files
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 <[email protected]> TryBot-Result: Gobot Gobot <[email protected]> Reviewed-by: Brad Fitzpatrick <[email protected]> Reviewed-by: Russ Cox <[email protected]>
1 parent 0ea1c1f commit b64b3a7

File tree

2 files changed

+19
-11
lines changed

2 files changed

+19
-11
lines changed

src/cmd/go/note.go

+19-8
Original file line numberDiff line numberDiff line change
@@ -121,15 +121,26 @@ func readELFGoBuildID(filename string, f *os.File, data []byte) (buildid string,
121121
return "", err
122122
}
123123
}
124-
nameSize := ef.ByteOrder.Uint32(note)
125-
valSize := ef.ByteOrder.Uint32(note[4:])
126-
tag := ef.ByteOrder.Uint32(note[8:])
127-
name := note[12:16]
128-
if nameSize != 4 || 16+valSize > uint32(len(note)) || tag != elfGoBuildIDTag || !bytes.Equal(name, elfGoNote) {
129-
continue
130-
}
131124

132-
return string(note[16 : 16+valSize]), nil
125+
filesz := p.Filesz
126+
for filesz >= 16 {
127+
nameSize := ef.ByteOrder.Uint32(note)
128+
valSize := ef.ByteOrder.Uint32(note[4:])
129+
tag := ef.ByteOrder.Uint32(note[8:])
130+
name := note[12:16]
131+
if nameSize == 4 && 16+valSize <= uint32(len(note)) && tag == elfGoBuildIDTag && bytes.Equal(name, elfGoNote) {
132+
return string(note[16 : 16+valSize]), nil
133+
}
134+
135+
nameSize = (nameSize + 3) &^ 3
136+
valSize = (valSize + 3) &^ 3
137+
notesz := uint64(12 + nameSize + valSize)
138+
if filesz <= notesz {
139+
break
140+
}
141+
filesz -= notesz
142+
note = note[notesz:]
143+
}
133144
}
134145

135146
// No note. Treat as successful but build ID empty.

src/cmd/go/note_test.go

-3
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,6 @@ func TestNoteReading2K(t *testing.T) {
2828
}
2929

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

0 commit comments

Comments
 (0)