Skip to content

Commit 5e620b0

Browse files
committed
fix: drop runtime relationship
Signed-off-by: knqyf263 <[email protected]>
1 parent 1e1fe20 commit 5e620b0

File tree

6 files changed

+68
-29
lines changed

6 files changed

+68
-29
lines changed

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

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -50,12 +50,6 @@ func (p *Parser) Parse(r xio.ReadSeekerAt) ([]types.Library, []types.Dependency,
5050

5151
libs := make([]types.Library, 0, len(info.Deps)+2)
5252
libs = append(libs, []types.Library{
53-
{
54-
// Add the Go version used to build this binary.
55-
Name: "stdlib",
56-
Version: strings.TrimPrefix(info.GoVersion, "go"),
57-
Relationship: types.RelationshipRuntime,
58-
},
5953
{
6054
// Add main module
6155
Name: info.Main.Path,
@@ -65,6 +59,12 @@ func (p *Parser) Parse(r xio.ReadSeekerAt) ([]types.Library, []types.Dependency,
6559
Version: p.checkVersion(info.Main.Path, info.Main.Version),
6660
Relationship: types.RelationshipRoot,
6761
},
62+
{
63+
// Add the Go version used to build this binary.
64+
Name: "stdlib",
65+
Version: strings.TrimPrefix(info.GoVersion, "go"),
66+
Relationship: types.RelationshipDirect, // Considered a direct dependency as the main module depends on the standard packages.
67+
},
6868
}...)
6969

7070
for _, dep := range info.Deps {

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

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -13,16 +13,16 @@ import (
1313

1414
func TestParse(t *testing.T) {
1515
wantLibs := []types.Library{
16-
{
17-
Name: "stdlib",
18-
Version: "1.15.2",
19-
Relationship: types.RelationshipRuntime,
20-
},
2116
{
2217
Name: "github.com/aquasecurity/test",
2318
Version: "",
2419
Relationship: types.RelationshipRoot,
2520
},
21+
{
22+
Name: "stdlib",
23+
Version: "1.15.2",
24+
Relationship: types.RelationshipDirect,
25+
},
2626
{
2727
Name: "github.com/aquasecurity/go-pep440-version",
2828
Version: "v0.0.0-20210121094942-22b2f8951d46",
@@ -62,16 +62,16 @@ func TestParse(t *testing.T) {
6262
name: "with replace directive",
6363
inputFile: "testdata/replace.elf",
6464
want: []types.Library{
65-
{
66-
Name: "stdlib",
67-
Version: "1.16.4",
68-
Relationship: types.RelationshipRuntime,
69-
},
7065
{
7166
Name: "github.com/ebati/trivy-mod-parse",
7267
Version: "",
7368
Relationship: types.RelationshipRoot,
7469
},
70+
{
71+
Name: "stdlib",
72+
Version: "1.16.4",
73+
Relationship: types.RelationshipDirect,
74+
},
7575
{
7676
Name: "github.com/davecgh/go-spew",
7777
Version: "v1.1.1",
@@ -86,16 +86,16 @@ func TestParse(t *testing.T) {
8686
name: "with semver main module version",
8787
inputFile: "testdata/semver-main-module-version.macho",
8888
want: []types.Library{
89-
{
90-
Name: "stdlib",
91-
Version: "1.20.6",
92-
Relationship: types.RelationshipRuntime,
93-
},
9489
{
9590
Name: "go.etcd.io/bbolt",
9691
Version: "v1.3.5",
9792
Relationship: types.RelationshipRoot,
9893
},
94+
{
95+
Name: "stdlib",
96+
Version: "1.20.6",
97+
Relationship: types.RelationshipDirect,
98+
},
9999
},
100100
},
101101
{

pkg/dependency/types/types.go

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -89,15 +89,13 @@ type Relationship int
8989

9090
const (
9191
RelationshipUnknown Relationship = iota
92-
RelationshipRuntime
9392
RelationshipRoot
9493
RelationshipDirect
9594
RelationshipIndirect
9695
)
9796

9897
var relationshipNames = [...]string{
9998
"unknown",
100-
"runtime",
10199
"root",
102100
"direct",
103101
"indirect",

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

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -29,16 +29,16 @@ 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-
Relationship: types.RelationshipRuntime,
36-
},
3732
{
3833
Name: "github.com/aquasecurity/test",
3934
Version: "",
4035
Relationship: types.RelationshipRoot,
4136
},
37+
{
38+
Name: "stdlib",
39+
Version: "1.15.2",
40+
Relationship: types.RelationshipDirect,
41+
},
4242
{
4343
Name: "github.com/aquasecurity/go-pep440-version",
4444
Version: "v0.0.0-20210121094942-22b2f8951d46",

pkg/fanal/types/artifact.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,6 @@ type Relationship = godeptypes.Relationship
7171

7272
const (
7373
RelationshipUnknown = godeptypes.RelationshipUnknown
74-
RelationshipRuntime = godeptypes.RelationshipRuntime
7574
RelationshipRoot = godeptypes.RelationshipRoot
7675
RelationshipDirect = godeptypes.RelationshipDirect
7776
RelationshipIndirect = godeptypes.RelationshipIndirect

pkg/sbom/io/encode_test.go

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -351,6 +351,19 @@ func TestEncoder_Encode(t *testing.T) {
351351
},
352352
Relationship: ftypes.RelationshipIndirect,
353353
},
354+
{
355+
356+
Name: "stdlib",
357+
Version: "1.22.1",
358+
Identifier: ftypes.PkgIdentifier{
359+
PURL: &packageurl.PackageURL{
360+
Type: packageurl.TypeGolang,
361+
Name: "stdlib",
362+
Version: "1.22.1",
363+
},
364+
},
365+
Relationship: ftypes.RelationshipDirect,
366+
},
354367
},
355368
},
356369
},
@@ -460,6 +473,30 @@ func TestEncoder_Encode(t *testing.T) {
460473
BOMRef: "pkg:golang/github.com/org/[email protected]",
461474
},
462475
},
476+
uuid.MustParse("3ff14136-e09f-4df9-80ea-000000000006"): {
477+
Type: core.TypeLibrary,
478+
Name: "stdlib",
479+
Version: "1.22.1",
480+
SrcFile: "test",
481+
Properties: []core.Property{
482+
{
483+
Name: core.PropertyPkgID,
484+
485+
},
486+
{
487+
Name: core.PropertyPkgType,
488+
Value: "gobinary",
489+
},
490+
},
491+
PkgID: core.PkgID{
492+
PURL: &packageurl.PackageURL{
493+
Type: packageurl.TypeGolang,
494+
Name: "stdlib",
495+
Version: "1.22.1",
496+
},
497+
BOMRef: "pkg:golang/[email protected]",
498+
},
499+
},
463500
},
464501
wantRels: map[uuid.UUID][]core.Relationship{
465502
uuid.MustParse("3ff14136-e09f-4df9-80ea-000000000001"): {
@@ -479,6 +516,10 @@ func TestEncoder_Encode(t *testing.T) {
479516
Dependency: uuid.MustParse("3ff14136-e09f-4df9-80ea-000000000004"),
480517
Type: core.RelationshipDependsOn,
481518
},
519+
{
520+
Dependency: uuid.MustParse("3ff14136-e09f-4df9-80ea-000000000006"),
521+
Type: core.RelationshipDependsOn,
522+
},
482523
},
483524
uuid.MustParse("3ff14136-e09f-4df9-80ea-000000000004"): {
484525
{
@@ -487,6 +528,7 @@ func TestEncoder_Encode(t *testing.T) {
487528
},
488529
},
489530
uuid.MustParse("3ff14136-e09f-4df9-80ea-000000000005"): nil,
531+
uuid.MustParse("3ff14136-e09f-4df9-80ea-000000000006"): nil,
490532
},
491533
wantVulns: map[uuid.UUID][]core.Vulnerability{},
492534
},

0 commit comments

Comments
 (0)