Skip to content

Commit

Permalink
fix(vuln): In alpine use Name as SrcName (#3079)
Browse files Browse the repository at this point in the history
  • Loading branch information
behara committed Oct 27, 2022
1 parent 9e649b8 commit 0765148
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 1 deletion.
6 changes: 5 additions & 1 deletion pkg/detector/ospkg/alpine/alpine.go
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,11 @@ func (s *Scanner) Detect(osVer string, repo *ftypes.Repository, pkgs []ftypes.Pa

var vulns []types.DetectedVulnerability
for _, pkg := range pkgs {
advisories, err := s.vs.Get(stream, pkg.SrcName)
srcName := pkg.SrcName
if srcName == "" {
srcName = pkg.Name
}
advisories, err := s.vs.Get(stream, srcName)
if err != nil {
return nil, xerrors.Errorf("failed to get alpine advisories: %w", err)
}
Expand Down
31 changes: 31 additions & 0 deletions pkg/detector/ospkg/alpine/alpine_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,37 @@ func TestScanner_Detect(t *testing.T) {
},
wantErr: "failed to get alpine advisories",
},
{
name: "No src name",
fixtures: []string{"testdata/fixtures/alpine.yaml", "testdata/fixtures/data-source.yaml"},
args: args{
osVer: "3.9.3",
repo: &ftypes.Repository{
Family: os.Alpine,
Release: "3.10",
},
pkgs: []ftypes.Package{
{
Name: "jq",
Version: "1.6-r0",
SrcVersion: "1.6-r0",
},
},
},
want: []types.DetectedVulnerability{
{
PkgName: "jq",
VulnerabilityID: "CVE-2020-1234",
InstalledVersion: "1.6-r0",
FixedVersion: "1.6-r1",
DataSource: &dbTypes.DataSource{
ID: vulnerability.Alpine,
Name: "Alpine Secdb",
URL: "https://secdb.alpinelinux.org/",
},
},
},
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
Expand Down

0 comments on commit 0765148

Please sign in to comment.