-
Notifications
You must be signed in to change notification settings - Fork 61
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
internal/vulncheck/internal/buildinfo: support stripped darwin binaries
With go1.22 and its prereleases, binaries are also stripped on darwin. This cannot be observed by checking emptiness of the symbol table, yet by non-existence of program symbols, "runtime.main" being a symbol that every program should have. Fixes golang/go#61051 Change-Id: If39214df9531bee66931a4155a2a8fbfbf3823cb Reviewed-on: https://go-review.googlesource.com/c/vuln/+/522157 Run-TryBot: Zvonimir Pavlinovic <[email protected]> Reviewed-by: Cherry Mui <[email protected]> TryBot-Result: Gopher Robot <[email protected]>
- Loading branch information
1 parent
3881ca8
commit 712bbae
Showing
6 changed files
with
125 additions
and
58 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
38 changes: 38 additions & 0 deletions
38
internal/vulncheck/internal/buildinfo/additions_stripped_122_test.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
// Copyright 2023 The Go Authors. All rights reserved. | ||
// Use of this source code is governed by a BSD-style | ||
// license that can be found in the LICENSE file. | ||
|
||
//go:build go1.22 | ||
// +build go1.22 | ||
|
||
package buildinfo | ||
|
||
import ( | ||
"os" | ||
"testing" | ||
|
||
"golang.org/x/vuln/internal/test" | ||
) | ||
|
||
// TestStrippedBinary checks that there is no symbol table for | ||
// stripped binaries. | ||
func TestStrippedBinary(t *testing.T) { | ||
testAll(t, []string{"linux", "windows", "freebsd", "darwin"}, []string{"amd64", "386", "arm", "arm64"}, | ||
func(t *testing.T, goos, goarch string) { | ||
binary, done := test.GoBuild(t, "testdata", "", true, "GOOS", goos, "GOARCH", goarch) | ||
defer done() | ||
|
||
f, err := os.Open(binary) | ||
if err != nil { | ||
t.Fatal(err) | ||
} | ||
defer f.Close() | ||
_, syms, _, err := ExtractPackagesAndSymbols(f) | ||
if err != nil { | ||
t.Fatal(err) | ||
} | ||
if syms != nil { | ||
t.Errorf("want empty symbol table; got %v symbols", len(syms)) | ||
} | ||
}) | ||
} |
68 changes: 68 additions & 0 deletions
68
internal/vulncheck/internal/buildinfo/additions_stripped_test.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
// Copyright 2023 The Go Authors. All rights reserved. | ||
// Use of this source code is governed by a BSD-style | ||
// license that can be found in the LICENSE file. | ||
|
||
//go:build go1.18 && !go1.22 | ||
// +build go1.18,!go1.22 | ||
|
||
package buildinfo | ||
|
||
import ( | ||
"os" | ||
"testing" | ||
|
||
"github.com/google/go-cmp/cmp" | ||
"golang.org/x/vuln/internal/test" | ||
) | ||
|
||
// TestStrippedBinary checks that there is no symbol table for | ||
// stripped binaries. This does not include darwin binaries. | ||
// For more info, see #61051. | ||
func TestStrippedBinary(t *testing.T) { | ||
// We exclude darwin as its stripped binaries seem to | ||
// preserve the symbol table. See TestStrippedDarwin. | ||
testAll(t, []string{"linux", "windows", "freebsd"}, []string{"amd64", "386", "arm", "arm64"}, | ||
func(t *testing.T, goos, goarch string) { | ||
binary, done := test.GoBuild(t, "testdata", "", true, "GOOS", goos, "GOARCH", goarch) | ||
defer done() | ||
|
||
f, err := os.Open(binary) | ||
if err != nil { | ||
t.Fatal(err) | ||
} | ||
defer f.Close() | ||
_, syms, _, err := ExtractPackagesAndSymbols(f) | ||
if err != nil { | ||
t.Fatal(err) | ||
} | ||
if syms != nil { | ||
t.Errorf("want empty symbol table; got %v symbols", len(syms)) | ||
} | ||
}) | ||
} | ||
|
||
// TestStrippedDarwin checks that the symbol table exists and | ||
// is complete on darwin even in the presence of stripping. | ||
// For more info, see #61051. | ||
func TestStrippedDarwin(t *testing.T) { | ||
testAll(t, []string{"darwin"}, []string{"amd64", "386"}, | ||
func(t *testing.T, goos, goarch string) { | ||
binary, done := test.GoBuild(t, "testdata", "", true, "GOOS", goos, "GOARCH", goarch) | ||
defer done() | ||
|
||
f, err := os.Open(binary) | ||
if err != nil { | ||
t.Fatal(err) | ||
} | ||
defer f.Close() | ||
_, syms, _, err := ExtractPackagesAndSymbols(f) | ||
if err != nil { | ||
t.Fatal(err) | ||
} | ||
got := syms["main"] | ||
want := []string{"f", "g", "main"} | ||
if !cmp.Equal(got, want) { | ||
t.Errorf("\ngot %q\nwant %q", got, want) | ||
} | ||
}) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters