diff --git a/pkg/dependency/parser/golang/binary/parse.go b/pkg/dependency/parser/golang/binary/parse.go index 171d3574800e..a50397db11b2 100644 --- a/pkg/dependency/parser/golang/binary/parse.go +++ b/pkg/dependency/parser/golang/binary/parse.go @@ -52,6 +52,10 @@ func (p *Parser) Parse(r xio.ReadSeekerAt) ([]ftypes.Package, []ftypes.Dependenc return nil, nil, convertError(err) } + // Ex: "go1.22.3 X:boringcrypto" + stdlibVersion := strings.TrimPrefix(info.GoVersion, "go") + stdlibVersion, _, _ = strings.Cut(stdlibVersion, " ") + ldflags := p.ldFlags(info.Settings) pkgs := make(ftypes.Packages, 0, len(info.Deps)+2) pkgs = append(pkgs, []ftypes.Package{ @@ -69,7 +73,7 @@ func (p *Parser) Parse(r xio.ReadSeekerAt) ([]ftypes.Package, []ftypes.Dependenc { // Add the Go version used to build this binary. Name: "stdlib", - Version: strings.TrimPrefix(info.GoVersion, "go"), + Version: stdlibVersion, Relationship: ftypes.RelationshipDirect, // Considered a direct dependency as the main module depends on the standard packages. }, }...) diff --git a/pkg/dependency/parser/golang/binary/parse_test.go b/pkg/dependency/parser/golang/binary/parse_test.go index e3144064ffe3..02bcf12c0181 100644 --- a/pkg/dependency/parser/golang/binary/parse_test.go +++ b/pkg/dependency/parser/golang/binary/parse_test.go @@ -114,6 +114,22 @@ func TestParse(t *testing.T) { }, }, }, + { + name: "goexperiment", + inputFile: "testdata/goexperiment", + want: []ftypes.Package{ + { + Name: "", + Version: "", + Relationship: ftypes.RelationshipRoot, + }, + { + Name: "stdlib", + Version: "1.22.1", + Relationship: ftypes.RelationshipDirect, + }, + }, + }, { name: "sad path", inputFile: "testdata/dummy", diff --git a/pkg/dependency/parser/golang/binary/testdata/goexperiment b/pkg/dependency/parser/golang/binary/testdata/goexperiment new file mode 100755 index 000000000000..af68dd8a351d Binary files /dev/null and b/pkg/dependency/parser/golang/binary/testdata/goexperiment differ