Skip to content

Commit 9d61777

Browse files
authored
fix(oracle): handle advisories contain ksplice versions (#1209)
* fix(oracle): handle advisories contain ksplice versions Improve a handling of advisories contain ksplice versions: * when one of them doesn't have ksplice, we'll also skip it * extract kspliceX and compare it with kspliceY in advisories * if kspliceX and kspliceY are different, we will skip the advisory. Fixes #1205 * fix(oracle): handle advisories contain ksplice versions simplify code and remove duplicated tests Fixes #1205 * run go fmt
1 parent 5d57dea commit 9d61777

File tree

2 files changed

+36
-2
lines changed

2 files changed

+36
-2
lines changed

pkg/detector/ospkg/oracle/oracle.go

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,16 @@ func NewScanner() *Scanner {
4444
}
4545
}
4646

47+
func extractKsplice(v string) string {
48+
subs := strings.Split(strings.ToLower(v), ".")
49+
for _, s := range subs {
50+
if strings.HasPrefix(s, "ksplice") {
51+
return s
52+
}
53+
}
54+
return ""
55+
}
56+
4757
// Detect scans and return vulnerability in Oracle scanner
4858
func (s *Scanner) Detect(osVer string, pkgs []ftypes.Package) ([]types.DetectedVulnerability, error) {
4959
log.Logger.Info("Detecting Oracle Linux vulnerabilities...")
@@ -65,10 +75,13 @@ func (s *Scanner) Detect(osVer string, pkgs []ftypes.Package) ([]types.DetectedV
6575
installed := utils.FormatVersion(pkg)
6676
installedVersion := version.NewVersion(installed)
6777
for _, adv := range advisories {
68-
// Skip if only one of them contains .ksplice1.
69-
if strings.Contains(adv.FixedVersion, ".ksplice1.") != strings.Contains(pkg.Release, ".ksplice1.") {
78+
// when one of them doesn't have ksplice, we'll also skip it
79+
// extract kspliceX and compare it with kspliceY in advisories
80+
// if kspliceX and kspliceY are different, we will skip the advisory
81+
if extractKsplice(adv.FixedVersion) != extractKsplice(pkg.Release) {
7082
continue
7183
}
84+
7285
fixedVersion := version.NewVersion(adv.FixedVersion)
7386
vuln := types.DetectedVulnerability{
7487
VulnerabilityID: adv.VulnerabilityID,

pkg/detector/ospkg/oracle/oracle_test.go

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,27 @@ func TestScanner_Detect(t *testing.T) {
151151
},
152152
want: nil,
153153
},
154+
{
155+
name: "the installed version has ksplice2",
156+
fixtures: []string{"testdata/fixtures/oracle7.yaml"},
157+
args: args{
158+
osVer: "7",
159+
pkgs: []ftypes.Package{
160+
{
161+
Name: "glibc",
162+
Epoch: 2,
163+
Version: "2.28",
164+
Release: "151.0.1.ksplice2.el8",
165+
Arch: "x86_64",
166+
SrcEpoch: 2,
167+
SrcName: "glibc",
168+
SrcVersion: "2.28",
169+
SrcRelease: "151.0.1.ksplice2.el8",
170+
},
171+
},
172+
},
173+
want: nil,
174+
},
154175
{
155176
name: "with ksplice",
156177
fixtures: []string{"testdata/fixtures/oracle7.yaml"},

0 commit comments

Comments
 (0)