Skip to content

Commit 7dfa436

Browse files
aegEiji Itospiffcs
authored
Add "Alpine Linux" to IDMapping; handle no CPEs error in findApkPackage. (#2040)
* Add "Alpine Linux" to IDMapping; handle no CPEs error in findApkPackage. Signed-off-by: Eiji Ito <[email protected]> * Remove unused errNoCPEs and update error handling in findApkPackage function. Signed-off-by: Eiji Ito <[email protected]> * test: prove test fails without fix Signed-off-by: Christopher Phillips <[email protected]> * fix: revert contributed fix Signed-off-by: Christopher Phillips <[email protected]> --------- Signed-off-by: Eiji Ito <[email protected]> Signed-off-by: Christopher Phillips <[email protected]> Co-authored-by: Eiji Ito <[email protected]> Co-authored-by: Christopher Phillips <[email protected]>
1 parent a758b01 commit 7dfa436

File tree

3 files changed

+83
-1
lines changed

3 files changed

+83
-1
lines changed

grype/distro/type.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@ var IDMapping = map[string]Type{
6464
"centos": CentOS,
6565
"fedora": Fedora,
6666
"alpine": Alpine,
67+
"Alpine Linux": Alpine,
6768
"busybox": Busybox,
6869
"amzn": AmazonLinux,
6970
"ol": OracleLinux,

grype/matcher/apk/matcher.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -146,8 +146,9 @@ func (m *Matcher) findApkPackage(store vulnerability.Provider, d *distro.Distro,
146146
return nil, err
147147
}
148148

149+
// TODO: are there other errors that we should handle here that causes this to short circuit
149150
cpeMatches, err := m.cpeMatchesWithoutSecDBFixes(store, d, p)
150-
if err != nil {
151+
if err != nil && !errors.Is(err, search.ErrEmptyCPEMatch) {
151152
return nil, err
152153
}
153154

grype/matcher/apk/matcher_test.go

Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -635,6 +635,86 @@ func TestDistroMatchBySourceIndirection(t *testing.T) {
635635
assertMatches(t, expected, actual)
636636
}
637637

638+
func TestSecDBMatchesStillCountedWithCpeErrors(t *testing.T) {
639+
// this should match the test package
640+
// the test package will have no CPE causing an error,
641+
// but the error should not cause the secDB matches to fail
642+
secDbVuln := grypeDB.Vulnerability{
643+
ID: "CVE-2020-2",
644+
VersionConstraint: "<= 1.3.3-r0",
645+
VersionFormat: "apk",
646+
Namespace: "secdb:distro:alpine:3.12",
647+
}
648+
649+
store := mockStore{
650+
backend: map[string]map[string][]grypeDB.Vulnerability{
651+
"secdb:distro:alpine:3.12": {
652+
"musl": []grypeDB.Vulnerability{secDbVuln},
653+
},
654+
},
655+
}
656+
657+
provider, err := db.NewVulnerabilityProvider(&store)
658+
require.NoError(t, err)
659+
660+
m := Matcher{}
661+
d, err := distro.New(distro.Alpine, "3.12.0", "")
662+
if err != nil {
663+
t.Fatalf("failed to create a new distro: %+v", err)
664+
}
665+
666+
p := pkg.Package{
667+
ID: pkg.ID(uuid.NewString()),
668+
Name: "musl-utils",
669+
Version: "1.3.2-r0",
670+
Type: syftPkg.ApkPkg,
671+
Upstreams: []pkg.UpstreamPackage{
672+
{
673+
Name: "musl",
674+
},
675+
},
676+
CPEs: []cpe.CPE{},
677+
}
678+
679+
vulnFound, err := vulnerability.NewVulnerability(secDbVuln)
680+
assert.NoError(t, err)
681+
682+
expected := []match.Match{
683+
{
684+
685+
Vulnerability: *vulnFound,
686+
Package: p,
687+
Details: []match.Detail{
688+
{
689+
Type: match.ExactIndirectMatch,
690+
Confidence: 1.0,
691+
SearchedBy: map[string]interface{}{
692+
"distro": map[string]string{
693+
"type": d.Type.String(),
694+
"version": d.RawVersion,
695+
},
696+
"package": map[string]string{
697+
"name": "musl",
698+
"version": p.Version,
699+
},
700+
"namespace": "secdb:distro:alpine:3.12",
701+
},
702+
Found: map[string]interface{}{
703+
"versionConstraint": vulnFound.Constraint.String(),
704+
"vulnerabilityID": "CVE-2020-2",
705+
},
706+
Matcher: match.ApkMatcher,
707+
},
708+
},
709+
},
710+
}
711+
712+
actual, err := m.Match(provider, d, p)
713+
assert.NoError(t, err)
714+
715+
assertMatches(t, expected, actual)
716+
}
717+
638718
func TestNVDMatchBySourceIndirection(t *testing.T) {
639719
nvdVuln := grypeDB.Vulnerability{
640720
ID: "CVE-2020-1",

0 commit comments

Comments
 (0)