Skip to content
This repository was archived by the owner on Nov 26, 2024. It is now read-only.

Commit b27a348

Browse files
authored
Build info (#7)
Using buildinfo to get depedencies list
1 parent 3ca822d commit b27a348

4 files changed

Lines changed: 12 additions & 25 deletions

File tree

go.mod

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
module github.com/intercloud/gobinsec
22

3-
go 1.17
3+
go 1.18
44

55
require (
66
github.com/bradfitz/gomemcache v0.0.0-20220106215444-fb4bf637b56d
@@ -13,5 +13,5 @@ require (
1313
require (
1414
github.com/mattn/go-colorable v0.1.12 // indirect
1515
github.com/mattn/go-isatty v0.0.14 // indirect
16-
golang.org/x/sys v0.0.0-20220408201424-a24fb2fb8a0f // indirect
16+
golang.org/x/sys v0.0.0-20220412211240-33da011f77ad // indirect
1717
)

go.sum

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,8 @@ golang.org/x/sys v0.0.0-20200116001909-b77594299b42/go.mod h1:h1NjWce9XRLGQEsW7w
1616
golang.org/x/sys v0.0.0-20200223170610-d5e6a3e2c0ae/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
1717
golang.org/x/sys v0.0.0-20210630005230-0f9fa26af87c/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
1818
golang.org/x/sys v0.0.0-20210927094055-39ccf1dd6fa6/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
19-
golang.org/x/sys v0.0.0-20220408201424-a24fb2fb8a0f h1:8w7RhxzTVgUzw/AH/9mUV5q0vMgy40SQRursCcfmkCw=
20-
golang.org/x/sys v0.0.0-20220408201424-a24fb2fb8a0f/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
19+
golang.org/x/sys v0.0.0-20220412211240-33da011f77ad h1:ntjMns5wyP/fN65tdBD4g8J5w8n015+iIIs9rtjXkY0=
20+
golang.org/x/sys v0.0.0-20220412211240-33da011f77ad/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
2121
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM=
2222
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
2323
gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b h1:h8qDotaEPuJATrMmW04NCwg7v22aHH28wwpauUhK9Oo=

gobinsec/binary.go

Lines changed: 7 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package gobinsec
22

33
import (
4+
"debug/buildinfo"
45
"fmt"
56
"os"
67
"path/filepath"
@@ -38,31 +39,17 @@ func NewBinary(path string) (*Binary, error) {
3839
return &binary, nil
3940
}
4041

41-
// GetDependencies gets dependencies analyzing binary
42+
// GetDependencies gets dependencies analyzing binary with buildinfo
4243
func (b *Binary) GetDependencies() error {
43-
stdout, stderr, err := ExecCommand("go", "version", "-m", b.Path)
44+
info, err := buildinfo.ReadFile(b.Path)
4445
if err != nil {
4546
return err
4647
}
47-
if stderr != "" {
48-
return fmt.Errorf(stderr)
49-
}
50-
lines := strings.Split(stdout, "\n")
51-
if len(lines) < MinimumBinaryLines {
52-
return fmt.Errorf(stdout)
53-
}
54-
for _, line := range lines[3:] {
55-
line = strings.TrimSpace(line)
56-
if line == "" {
57-
continue
58-
}
59-
parts := strings.Split(line, "\t")
60-
if len(parts) < MinimumBinaryDependencyFields {
61-
continue
48+
for _, dep := range info.Deps {
49+
for dep.Replace != nil {
50+
dep = dep.Replace
6251
}
63-
name := parts[1]
64-
version := parts[2]
65-
dependency, err := NewDependency(name, version)
52+
dependency, err := NewDependency(dep.Path, dep.Version)
6653
if err != nil {
6754
return err
6855
}

gobinsec/dependency.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ func (d *Dependency) LoadVulnerabilities() error {
3838
if config.APIKey != "" {
3939
url += "&apiKey=" + config.APIKey
4040
}
41-
response, err := http.Get(url) // nolint:noctx,gosec // it's safe!
41+
response, err := http.Get(url) // nolint:gosec // it's safe!
4242
if err != nil {
4343
return fmt.Errorf("calling NVD: %v", err)
4444
}

0 commit comments

Comments
 (0)