Skip to content

Commit

Permalink
Add photon matcher. (#185)
Browse files Browse the repository at this point in the history
Co-authored-by: Louis DeLosSantos <ldelossa.ld@gmail.com>
  • Loading branch information
ashwin-h and Louis DeLosSantos committed May 29, 2020
1 parent c4a279b commit c87a91c
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 0 deletions.
2 changes: 2 additions & 0 deletions libvuln/opts.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import (
"github.com/quay/claircore/python"
"github.com/quay/claircore/rhel"
"github.com/quay/claircore/ubuntu"
"github.com/quay/claircore/photon"
)

const (
Expand Down Expand Up @@ -71,6 +72,7 @@ var defaultMatchers = []driver.Matcher{
&python.Matcher{},
&ubuntu.Matcher{},
&rhel.Matcher{},
&photon.Matcher{},
}

// parse is an internal method for constructing
Expand Down
48 changes: 48 additions & 0 deletions photon/matcher.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
package photon

import (
version "github.com/knqyf263/go-rpm-version"

"github.com/quay/claircore"
"github.com/quay/claircore/libvuln/driver"
)

// Matcher implements driver.Matcher.
type Matcher struct{}

var _ driver.Matcher = (*Matcher)(nil)

// Name implements driver.Matcher.
func (*Matcher) Name() string {
return "photon"
}

// Filter implements driver.Matcher.
func (*Matcher) Filter(record *claircore.IndexRecord) bool {
return record.Distribution != nil &&
record.Distribution.DID == "photon"
}

// Query implements driver.Matcher.
func (*Matcher) Query() []driver.MatchConstraint {
return []driver.MatchConstraint{
driver.DistributionDID,
driver.DistributionName,
driver.DistributionVersion,
}
}

// Vulnerable implements driver.Matcher.
func (*Matcher) Vulnerable(record *claircore.IndexRecord, vuln *claircore.Vulnerability) bool {
pkgVer, vulnVer := version.NewVersion(record.Package.Version), version.NewVersion(vuln.Package.Version)
// Assume the vulnerability record we have is for the last known vulnerable
// version, so greater versions aren't vulnerable.
cmp := func(i int) bool { return i != version.GREATER }
// But if it's explicitly marked as a fixed-in version, it't only vulnerable
// if less than that version.
if vuln.FixedInVersion != "" {
vulnVer = version.NewVersion(vuln.FixedInVersion)
cmp = func(i int) bool { return i == version.LESS }
}
return cmp(pkgVer.Compare(vulnVer))
}

0 comments on commit c87a91c

Please sign in to comment.