Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add photon matcher. #185

Merged
merged 2 commits into from
May 29, 2020
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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))
}