]> Cypherpunks repositories - gostls13.git/commitdiff
cmd/go: fix reading PT_NOTE segment with multiple notes
authorIan Lance Taylor <iant@golang.org>
Wed, 2 Dec 2015 05:16:29 +0000 (21:16 -0800)
committerIan Lance Taylor <iant@golang.org>
Wed, 2 Dec 2015 17:21:44 +0000 (17:21 +0000)
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>
src/cmd/go/note.go
src/cmd/go/note_test.go

index c7346a5731e61202957d2e3db8c503a2fb67aecb..f846eeb62b1cc22872720553f11413e98d9f9eb6 100644 (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.
index 0d43b9ec934cedcf0edd799db6b78b236a93f5b5..bfaa75f6c30cb2e77130114a3fd543c3c253bce0 100644 (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") }`)