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

formatters/trivy:fix - find correct line of dependency #882

Merged
merged 3 commits into from
Dec 21, 2021
Merged
Show file tree
Hide file tree
Changes from 2 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
4 changes: 3 additions & 1 deletion internal/services/formatters/generic/trivy/formatter.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ import (
"github.com/ZupIT/horusec/internal/helpers/messages"
"github.com/ZupIT/horusec/internal/services/formatters"
"github.com/ZupIT/horusec/internal/services/formatters/generic/trivy/entities"
"github.com/ZupIT/horusec/internal/utils/file"
vulnhash "github.com/ZupIT/horusec/internal/utils/vuln_hash"
)

Expand Down Expand Up @@ -164,8 +165,9 @@ func (f *Formatter) setVulnerabilities(cmd string, result *entities.Result, path
func (f *Formatter) setVulnerabilitiesOutput(vulnerabilities []*entities.Vulnerability, target string) {
for _, vuln := range vulnerabilities {
addVuln := f.getVulnBase()
addVuln.Code = fmt.Sprintf("%s v%s", vuln.PkgName, vuln.InstalledVersion)
_, _, addVuln.Line = file.GetDependencyInfo([]string{target}, addVuln.Code)
addVuln.File = target
addVuln.Code = vuln.PkgName
addVuln.Details = vuln.GetDetails()
addVuln.Severity = severities.GetSeverityByString(vuln.Severity)
addVuln = vulnhash.Bind(addVuln)
Expand Down
4 changes: 2 additions & 2 deletions internal/utils/file/file.go
Original file line number Diff line number Diff line change
Expand Up @@ -241,7 +241,7 @@ func GetDependencyCodeFilepathAndLine(
return "", "", ""
}

return getDependencyInfo(paths, dependency)
return GetDependencyInfo(paths, dependency)
}

// nolint: funlen
Expand Down Expand Up @@ -271,7 +271,7 @@ func getPathsByExtension(projectPath, subPath string, extensions ...string) ([]s
// The line and the dependency trimmed is also returned.
//
//nolint:funlen,gocyclo
func getDependencyInfo(paths []string, dependency string) (string, string, string) {
func GetDependencyInfo(paths []string, dependency string) (string, string, string) {
matheusalcantarazup marked this conversation as resolved.
Show resolved Hide resolved
var line int

for _, path := range paths {
Expand Down