Skip to content

Commit

Permalink
printresults:fix - duplicated vulnerability severities on result
Browse files Browse the repository at this point in the history
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 <[email protected]>
  • Loading branch information
matheusalcantarazup committed Dec 1, 2021
1 parent 00eb2bb commit 5002a2a
Showing 1 changed file with 6 additions and 5 deletions.
11 changes: 6 additions & 5 deletions internal/controllers/printresults/print_results.go
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
}
}

Expand Down

0 comments on commit 5002a2a

Please sign in to comment.