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

fix(oracle): handle advisories contain ksplice versions #1209

Merged
merged 3 commits into from
Sep 5, 2021

Conversation

afdesk
Copy link
Contributor

@afdesk afdesk commented Sep 2, 2021

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

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 aquasecurity#1205
Copy link
Collaborator

@knqyf263 knqyf263 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good! Thanks. I suggested some ideas to simplify code.

Comment on lines 47 to 58
func extractKspliceNumber(v string) string {
subs := strings.Split(strings.ToLower(v), "ksplice")
if len(subs) != 2 {
return ""
}
ns := strings.Split(subs[1], ".")
if len(ns) == 0 {
return ""
}
return ns[0]
}

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we can assume ksplice is separated by dot, how about this?

Suggested change
func extractKspliceNumber(v string) string {
subs := strings.Split(strings.ToLower(v), "ksplice")
if len(subs) != 2 {
return ""
}
ns := strings.Split(subs[1], ".")
if len(ns) == 0 {
return ""
}
return ns[0]
}
func extractKspliceNumber(v string) string {
subs := strings.Split(strings.ToLower(v), ".")
for _, s := range subs {
if strings.HasPrefix(v, "ksplice") {
return s
}
}
return ""
}

Comment on lines 83 to 90
if isKSlice := strings.Contains(adv.FixedVersion, ".ksplice"); isKSlice != strings.Contains(pkg.Release, ".ksplice") {
continue
} else if isKSlice {
releaseV := extractKspliceNumber(adv.FixedVersion)
fixedV := extractKspliceNumber(pkg.Release)
if releaseV != fixedV {
continue
}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we can simplify it.

Suggested change
if isKSlice := strings.Contains(adv.FixedVersion, ".ksplice"); isKSlice != strings.Contains(pkg.Release, ".ksplice") {
continue
} else if isKSlice {
releaseV := extractKspliceNumber(adv.FixedVersion)
fixedV := extractKspliceNumber(pkg.Release)
if releaseV != fixedV {
continue
}
if extractKspliceNumber(adv.FixedVersion) != extractKspliceNumber(pkg.Release) {
continue
}

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sure, your was is better!

Comment on lines 154 to 199
{
name: "the correct installed version without ksplice2",
fixtures: []string{"testdata/fixtures/oracle8.yaml"},
args: args{
osVer: "8",
pkgs: []ftypes.Package{
{
Name: "glibc",
Version: "2.28",
Release: "151.0.1.el8",
Arch: "x86_64",
SrcName: "glibc",
SrcVersion: "2.28",
SrcRelease: "151.0.1.el8",
},
},
},
want: nil,
},
{
name: "the correct installed version with ksplice2",
fixtures: []string{"testdata/fixtures/oracle8.yaml"},
args: args{
osVer: "8",
pkgs: []ftypes.Package{
{
Name: "glibc",
Epoch: 2,
Version: "2.28",
Release: "151.0.1.ksplice2.el8",
Arch: "x86_64",
SrcEpoch: 2,
SrcName: "glibc",
SrcVersion: "2.28",
SrcRelease: "151.0.1.ksplice2.el8",
},
},
},
want: nil,
},
{
name: "the installed version has ksplice1",
fixtures: []string{"testdata/fixtures/oracle8.yaml"},
args: args{
osVer: "8",
pkgs: []ftypes.Package{
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We already have the same test for ksplice1. These tests are duplicate. We should add only 1 test where the installed version has ksplice2.

Comment on lines 312 to 329
func TestGetKspliceNumber(t *testing.T) {
tests := []struct {
in string
res string
}{
{"", ""},
{"2:2.17-157.el7_3.4", ""},
{"2:2.17-157.ksplice1.el7_3.4", "1"},
{"2:2.28-151.0.1.ksplice2.el8", "2"},
{"2:2.28-151.0.1.ksplice2", "2"},
{"2:2.28-151.0.1.KSplice2", "2"},
}
for _, test := range tests {
if got := extractKspliceNumber(test.in); got != test.res {
t.Errorf("getKspliceNumber(%q) got %q, want %q", test.in, got, test.res)
}
}
}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can test this method through TestScanner_Detect

@knqyf263 knqyf263 merged commit 9d61777 into aquasecurity:main Sep 5, 2021
liamg pushed a commit that referenced this pull request Jun 7, 2022
* 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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

False ksplice vulnernerabilities reported
2 participants