Skip to content

Commit d82d6cb

Browse files
thepwagnerknqyf263
andauthored
feat(image): goversion as stdlib (aquasecurity#6277)
Co-authored-by: knqyf263 <[email protected]>
1 parent cfddfb3 commit d82d6cb

File tree

3 files changed

+25
-1
lines changed

3 files changed

+25
-1
lines changed

pkg/dependency/parser/golang/binary/parse.go

+5-1
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,11 @@ func (p *Parser) Parse(r xio.ReadSeekerAt) ([]types.Library, []types.Dependency,
4242
return nil, nil, convertError(err)
4343
}
4444

45-
libs := make([]types.Library, 0, len(info.Deps))
45+
libs := make([]types.Library, 0, len(info.Deps)+1)
46+
libs = append(libs, types.Library{
47+
Name: "stdlib",
48+
Version: strings.TrimPrefix(info.GoVersion, "go"),
49+
})
4650

4751
for _, dep := range info.Deps {
4852
// binaries with old go version may incorrectly add module in Deps

pkg/dependency/parser/golang/binary/parse_test.go

+16
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,10 @@ func TestParse(t *testing.T) {
2222
name: "ELF",
2323
inputFile: "testdata/test.elf",
2424
want: []types.Library{
25+
{
26+
Name: "stdlib",
27+
Version: "1.15.2",
28+
},
2529
{
2630
Name: "github.com/aquasecurity/go-pep440-version",
2731
Version: "v0.0.0-20210121094942-22b2f8951d46",
@@ -40,6 +44,10 @@ func TestParse(t *testing.T) {
4044
name: "PE",
4145
inputFile: "testdata/test.exe",
4246
want: []types.Library{
47+
{
48+
Name: "stdlib",
49+
Version: "1.15.2",
50+
},
4351
{
4452
Name: "github.com/aquasecurity/go-pep440-version",
4553
Version: "v0.0.0-20210121094942-22b2f8951d46",
@@ -58,6 +66,10 @@ func TestParse(t *testing.T) {
5866
name: "Mach-O",
5967
inputFile: "testdata/test.macho",
6068
want: []types.Library{
69+
{
70+
Name: "stdlib",
71+
Version: "1.15.2",
72+
},
6173
{
6274
Name: "github.com/aquasecurity/go-pep440-version",
6375
Version: "v0.0.0-20210121094942-22b2f8951d46",
@@ -76,6 +88,10 @@ func TestParse(t *testing.T) {
7688
name: "with replace directive",
7789
inputFile: "testdata/replace.elf",
7890
want: []types.Library{
91+
{
92+
Name: "stdlib",
93+
Version: "1.16.4",
94+
},
7995
{
8096
Name: "github.com/davecgh/go-spew",
8197
Version: "v1.1.1",

pkg/fanal/analyzer/language/golang/binary/binary_test.go

+4
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,10 @@ func Test_gobinaryLibraryAnalyzer_Analyze(t *testing.T) {
2929
Type: types.GoBinary,
3030
FilePath: "testdata/executable_gobinary",
3131
Libraries: types.Packages{
32+
{
33+
Name: "stdlib",
34+
Version: "1.15.2",
35+
},
3236
{
3337
Name: "github.com/aquasecurity/go-pep440-version",
3438
Version: "v0.0.0-20210121094942-22b2f8951d46",

0 commit comments

Comments
 (0)