From 5002a2ae9592cefdd69d83d6eaa43d77bf3e7039 Mon Sep 17 00:00:00 2001 From: Matheus Alcantara Date: Wed, 1 Dec 2021 14:27:26 -0300 Subject: [PATCH] printresults:fix - duplicated vulnerability severities on result On #760 we made an improvement on `getDefaultTotalVulnBySeverity` which reuse the map returned from `getDefaultCountBySeverity` as a value for all keys on the default map of vulnerability severities, but since a map in Go is a pointer we was using the same map to all keys and when we were going to count vulnerabilities by severity, we would update the same pointer for all the keys in that map, which caused inconsistent and duplicated values in the final result. This commit revert this change and call pr.getDefaultCountBySeverity for all keys on this map. Signed-off-by: Matheus Alcantara --- internal/controllers/printresults/print_results.go | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/internal/controllers/printresults/print_results.go b/internal/controllers/printresults/print_results.go index 2a83059ce..8cf53307a 100644 --- a/internal/controllers/printresults/print_results.go +++ b/internal/controllers/printresults/print_results.go @@ -263,12 +263,13 @@ func (pr *PrintResults) getTotalVulnsBySeverity() map[vulnerabilityenum.Type]map } func (pr *PrintResults) getDefaultTotalVulnBySeverity() map[vulnerabilityenum.Type]map[severities.Severity]int { - count := pr.getDefaultCountBySeverity() + // NOTE: Here we call pr.getDefaultCountBySeverity for each key on map + // to avoid reuse the same map pointer to all keys. return map[vulnerabilityenum.Type]map[severities.Severity]int{ - vulnerabilityenum.Vulnerability: count, - vulnerabilityenum.RiskAccepted: count, - vulnerabilityenum.FalsePositive: count, - vulnerabilityenum.Corrected: count, + vulnerabilityenum.Vulnerability: pr.getDefaultCountBySeverity(), + vulnerabilityenum.RiskAccepted: pr.getDefaultCountBySeverity(), + vulnerabilityenum.FalsePositive: pr.getDefaultCountBySeverity(), + vulnerabilityenum.Corrected: pr.getDefaultCountBySeverity(), } }