Skip to content

Commit

Permalink
fix(detect/oracle): handle ksplice advisories (#2003)
Browse files Browse the repository at this point in the history
  • Loading branch information
MaineK00n authored Aug 13, 2024
1 parent f14ca86 commit 6425193
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 2 deletions.
13 changes: 11 additions & 2 deletions oval/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -406,8 +406,8 @@ func isOvalDefAffected(def ovalmodels.Definition, req request, family, release s
continue
}

// /~https://github.com/aquasecurity/trivy/pull/745
if strings.Contains(req.versionRelease, ".ksplice1.") != strings.Contains(ovalPack.Version, ".ksplice1.") {
// /~https://github.com/aquasecurity/trivy/blob/08cc14bd2171afdc1973c6d614dd0d1fb82b7623/pkg/detector/ospkg/oracle/oracle.go#L72-L77
if family == constant.Oracle && extractOracleKsplice(ovalPack.Version) != extractOracleKsplice(req.versionRelease) {
continue
}

Expand Down Expand Up @@ -591,6 +591,15 @@ func rhelRebuildOSVersionToRHEL(ver string) string {
return rhelRebuildOSVerPattern.ReplaceAllString(ver, ".el$1")
}

func extractOracleKsplice(v string) string {
for _, s := range strings.Split(v, ".") {
if strings.HasPrefix(s, "ksplice") {
return s
}
}
return ""
}

// NewOVALClient returns a client for OVAL database
func NewOVALClient(family string, cnf config.GovalDictConf, o logging.LogOpts) (Client, error) {
if err := ovallog.SetLogger(o.LogToFile, o.LogDir, o.Debug, o.LogJSON); err != nil {
Expand Down
42 changes: 42 additions & 0 deletions oval/util_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1887,6 +1887,48 @@ func TestIsOvalDefAffected(t *testing.T) {
affected: true,
fixedIn: "2:2.17-106.0.1.ksplice1.el7_2.4",
},
// .ksplice2.
{
in: in{
family: constant.Oracle,
def: ovalmodels.Definition{
AffectedPacks: []ovalmodels.Package{
{
Name: "nginx",
Version: "2:2.17-106.0.1.ksplice2.el7_2.4",
Arch: "x86_64",
},
},
},
req: request{
packName: "nginx",
versionRelease: "2:2.17-107",
arch: "x86_64",
},
},
affected: false,
},
// in: .ksplice1. , req: .ksplice2.
{
in: in{
family: constant.Oracle,
def: ovalmodels.Definition{
AffectedPacks: []ovalmodels.Package{
{
Name: "nginx",
Version: "2:2.17-106.0.1.ksplice1.el7_2.4",
Arch: "x86_64",
},
},
},
req: request{
packName: "nginx",
versionRelease: "2:2.17-105.0.1.ksplice2.el7_2.4",
arch: "x86_64",
},
},
affected: false,
},
// same arch
{
in: in{
Expand Down

0 comments on commit 6425193

Please sign in to comment.