8000 fix: disregard RPM module build number in version comparison by willmurphyscode · Pull Request #2375 · anchore/grype · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

fix: disregard RPM module build number in version comparison #2375

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

Draft
wants to merge 3 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 21 additions & 1 deletion grype/version/rpm_version.go
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,27 @@ func (v rpmVersion) compare(v2 rpmVersion) int {
return ret
}

return compareRpmVersions(v.release, v2.release)
return compareRpmReleases(v.release, v2.release)
}

// compareRpmReleases normalizes two release strigns before
// calling compareRpmVersions to compare them.
// It normalize the release strings by removing the build number
// from the end:
// "1.module_el8.3.0+757+d382997d" -> "1.module_el8.3.0"
// This is important because the build numbers are not identical between CentOS
// 8 and RHEL 8, even for the same package version, leading to FPs or FNs.
func compareRpmReleases(a, b string) int {
if a == b {
return 0
}

a = strings.Replace(a, "module+el", "module_el", 1)
b = strings.Replace(b, "module+el", "module_el", 1)

trimmedA, _, _ := strings.Cut(a, "+")
trimmedB, _, _ := strings.Cut(b, "+")
return compareRpmVersions(trimmedA, trimmedB)
}

func epochIsPresent(epoch *int) bool {
Expand Down
12 changes: 11 additions & 1 deletion grype/version/rpm_version_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,22 @@ func TestVersionRpm(t *testing.T) {
{"1:2", "1", 1},
{"0:4.19.1-1.el7_5", "2:4.19.1-1.el7_5", -1},
{"4:1.2.3-3-el7_5", "1.2.3-el7_5~snapshot1", 1},
//Non-standard comparisons that ignore epochs due to only one being available
// Non-standard comparisons that ignore epochs due to only one being available
{"1:0", "1", -1},
{"2:4.19.01-1.el7_5", "4.19.1-1.el7_5", 0},
{"4.19.01-1.el7_5", "2:4.19.1-1.el7_5", 0},
{"4.19.0-1.el7_5", "12:4.19.0-1.el7", 1},
{"3:4.19.0-1.el7_5", "4.21.0-1.el7", -1},
// centos and rhel build numbers differ on same version of same package
// ensure these are equal.
{"3:10.3.28-1.module_el8.3.0+757+d382997d", "3:10.3.28-1.module+el8.3.0+10472+7adc332a", 0},
// some amazonlinux examples
{"2.13.0-2.amzn2023.0.2", "2.13.0-2.amzn2023.0.1", 1},
{"1.20.14-18.amzn2023.0.1", "1.20.14-18.amzn2023.0.2", -1},
// examples from oracle linux 8 for python38-tkinter ELSA-2021-9130
{"3.8.17-2.module+el8.9.0+90017+9913aa0c", "0:3.8.3-3.0.1.module+el8.3.0+el8+9681+09f2c1ca", 1},
// note that build number 9680 and 9681 are different, but that's not part of the version comparison
{"0:3.8.3-3.0.1.module+el8.3.0+el8+9680+09f2c1ca", "0:3.8.3-3.0.1.module+el8.3.0+el8+9681+09f2c1ca", 0},
}

for _, test := range tests {
Expand Down
2 changes: 1 addition & 1 deletion test/quality/vulnerability-match-labels
Submodule vulnerability-match-labels updated 27 files
+1 −1 .github/workflows/update-sboms.yaml
+3 −3 .github/workflows/validations.yaml
+0 −1 ...:524ff8a75f21fd886ec7ed82387766df386671e8b77e898d05786118d5b7880b/058f8107-9683-40a3-91b9-8c37e45c3c4f.json
+1 −0 ...:524ff8a75f21fd886ec7ed82387766df386671e8b77e898d05786118d5b7880b/10458d06-82c4-416a-a445-b3600c8896fd.json
+1 −0 ...:524ff8a75f21fd886ec7ed82387766df386671e8b77e898d05786118d5b7880b/1a69711a-ae27-4078-adc1-3be68beb2469.json
+1 −0 ...:524ff8a75f21fd886ec7ed82387766df386671e8b77e898d05786118d5b7880b/1f086e85-274b-4d9b-919b-9544638d4f14.json
+0 −1 ...:524ff8a75f21fd886ec7ed82387766df386671e8b77e898d05786118d5b7880b/20407ea8-e580-4164-965a-69992940c469.json
+1 −0 ...:524ff8a75f21fd886ec7ed82387766df386671e8b77e898d05786118d5b7880b/31256057-0b64-440a-9bc2-9b505d41c83e.json
+1 −0 ...:524ff8a75f21fd886ec7ed82387766df386671e8b77e898d05786118d5b7880b/43dc574c-6f0c-412a-be67-15b515bdfcfe.json
+1 −0 ...:524ff8a75f21fd886ec7ed82387766df386671e8b77e898d05786118d5b7880b/5edcac60-b0dd-4c36-8e9a-0b0a7c968296.json
+0 −1 ...:524ff8a75f21fd886ec7ed82387766df386671e8b77e898d05786118d5b7880b/6e70d9e6-ce7e-48c8-9cc4-bb05ecd1ab1a.json
+0 −1 ...:524ff8a75f21fd886ec7ed82387766df386671e8b77e898d05786118d5b7880b/7036d8c5-f895-411a-b6e6-9f97e988f310.json
+1 −0 ...:524ff8a75f21fd886ec7ed82387766df386671e8b77e898d05786118d5b7880b/754bcc84-842c-4eb3-be4a-cdb54fd30670.json
+1 −0 ...:524ff8a75f21fd886ec7ed82387766df386671e8b77e898d05786118d5b7880b/9797102d-c234-4d9c-be5b-ebc5c396c2a7.json
+1 −0 ...:524ff8a75f21fd886ec7ed82387766df386671e8b77e898d05786118d5b7880b/979eb758-6ae9-48c9-8574-fb9c88230de0.json
+1 −0 ...:524ff8a75f21fd886ec7ed82387766df386671e8b77e898d05786118d5b7880b/baa60507-9e8f-453c-8910-c992f1c2769b.json
+0 −1 ...:524ff8a75f21fd886ec7ed82387766df386671e8b77e898d05786118d5b7880b/c175a74d-34e6-4497-a0a0-6a66ee984017.json
+0 −1 ...:524ff8a75f21fd886ec7ed82387766df386671e8b77e898d05786118d5b7880b/c5a5f6bd-ce12-472c-aed1-382ca23f7826.json
+0 −1 ...:524ff8a75f21fd886ec7ed82387766df386671e8b77e898d05786118d5b7880b/c68569b5-5acc-4179-abb2-2ae2b6a4bb1a.json
+1 −0 ...:524ff8a75f21fd886ec7ed82387766df386671e8b77e898d05786118d5b7880b/d240a161-cf54-4692-8550-820092f79be1.json
+1 −0 ...:524ff8a75f21fd886ec7ed82387766df386671e8b77e898d05786118d5b7880b/d626ed06-a909-4718-860d-712d4d46811c.json
+1 −0 ...:524ff8a75f21fd886ec7ed82387766df386671e8b77e898d05786118d5b7880b/e3b7d71c-0173-4159-a747-cfaa5a31e0ac.json
+0 −1 ...:524ff8a75f21fd886ec7ed82387766df386671e8b77e898d05786118d5b7880b/e5052f97-6c44-45ee-972d-9775102da643.json
+0 −1 ...:524ff8a75f21fd886ec7ed82387766df386671e8b77e898d05786118d5b7880b/e98a52ce-1ae2-48dc-bc1f-6eea10604934.json
+1 −0 ...:524ff8a75f21fd886ec7ed82387766df386671e8b77e898d05786118d5b7880b/f41235c1-1cca-45a4-babc-99f438aeab60.json
+1 −0 ...:524ff8a75f21fd886ec7ed82387766df386671e8b77e898d05786118d5b7880b/f6be3ad6-8447-4bc0-842a-3fddfb1fe791.json
+1 −0 ...:524ff8a75f21fd886ec7ed82387766df386671e8b77e898d05786118d5b7880b/fa713860-cbb1-4b7c-aacc-f956ab647945.json
Loading
0