From d82d6cb73133a25e5c3f6e8d501cb2ac6512dc45 Mon Sep 17 00:00:00 2001 From: Pete Wagner <1559510+thepwagner@users.noreply.github.com> Date: Mon, 15 Apr 2024 14:25:04 -0400 Subject: [PATCH] feat(image): goversion as stdlib (#6277) Co-authored-by: knqyf263 --- pkg/dependency/parser/golang/binary/parse.go | 6 +++++- .../parser/golang/binary/parse_test.go | 16 ++++++++++++++++ .../language/golang/binary/binary_test.go | 4 ++++ 3 files changed, 25 insertions(+), 1 deletion(-) diff --git a/pkg/dependency/parser/golang/binary/parse.go b/pkg/dependency/parser/golang/binary/parse.go index 8bf9bf4dab3e..9a8289e8e06b 100644 --- a/pkg/dependency/parser/golang/binary/parse.go +++ b/pkg/dependency/parser/golang/binary/parse.go @@ -42,7 +42,11 @@ func (p *Parser) Parse(r xio.ReadSeekerAt) ([]types.Library, []types.Dependency, return nil, nil, convertError(err) } - libs := make([]types.Library, 0, len(info.Deps)) + libs := make([]types.Library, 0, len(info.Deps)+1) + libs = append(libs, types.Library{ + Name: "stdlib", + Version: strings.TrimPrefix(info.GoVersion, "go"), + }) for _, dep := range info.Deps { // binaries with old go version may incorrectly add module in Deps diff --git a/pkg/dependency/parser/golang/binary/parse_test.go b/pkg/dependency/parser/golang/binary/parse_test.go index cee58377ef25..f21dc2878d4f 100644 --- a/pkg/dependency/parser/golang/binary/parse_test.go +++ b/pkg/dependency/parser/golang/binary/parse_test.go @@ -22,6 +22,10 @@ func TestParse(t *testing.T) { name: "ELF", inputFile: "testdata/test.elf", want: []types.Library{ + { + Name: "stdlib", + Version: "1.15.2", + }, { Name: "github.com/aquasecurity/go-pep440-version", Version: "v0.0.0-20210121094942-22b2f8951d46", @@ -40,6 +44,10 @@ func TestParse(t *testing.T) { name: "PE", inputFile: "testdata/test.exe", want: []types.Library{ + { + Name: "stdlib", + Version: "1.15.2", + }, { Name: "github.com/aquasecurity/go-pep440-version", Version: "v0.0.0-20210121094942-22b2f8951d46", @@ -58,6 +66,10 @@ func TestParse(t *testing.T) { name: "Mach-O", inputFile: "testdata/test.macho", want: []types.Library{ + { + Name: "stdlib", + Version: "1.15.2", + }, { Name: "github.com/aquasecurity/go-pep440-version", Version: "v0.0.0-20210121094942-22b2f8951d46", @@ -76,6 +88,10 @@ func TestParse(t *testing.T) { name: "with replace directive", inputFile: "testdata/replace.elf", want: []types.Library{ + { + Name: "stdlib", + Version: "1.16.4", + }, { Name: "github.com/davecgh/go-spew", Version: "v1.1.1", diff --git a/pkg/fanal/analyzer/language/golang/binary/binary_test.go b/pkg/fanal/analyzer/language/golang/binary/binary_test.go index ca8434298cbb..0636efcb2bbd 100644 --- a/pkg/fanal/analyzer/language/golang/binary/binary_test.go +++ b/pkg/fanal/analyzer/language/golang/binary/binary_test.go @@ -29,6 +29,10 @@ func Test_gobinaryLibraryAnalyzer_Analyze(t *testing.T) { Type: types.GoBinary, FilePath: "testdata/executable_gobinary", Libraries: types.Packages{ + { + Name: "stdlib", + Version: "1.15.2", + }, { Name: "github.com/aquasecurity/go-pep440-version", Version: "v0.0.0-20210121094942-22b2f8951d46",