Skip to content

Commit

Permalink
feat(image): goversion as stdlib (#6277)
Browse files Browse the repository at this point in the history
Co-authored-by: knqyf263 <knqyf263@gmail.com>
  • Loading branch information
thepwagner and knqyf263 committed Apr 15, 2024
1 parent cfddfb3 commit d82d6cb
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 1 deletion.
6 changes: 5 additions & 1 deletion pkg/dependency/parser/golang/binary/parse.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
16 changes: 16 additions & 0 deletions pkg/dependency/parser/golang/binary/parse_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -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",
Expand All @@ -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",
Expand All @@ -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",
Expand Down
4 changes: 4 additions & 0 deletions pkg/fanal/analyzer/language/golang/binary/binary_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down

0 comments on commit d82d6cb

Please sign in to comment.