|
1 | 1 | package golinters
|
2 | 2 |
|
3 | 3 | import (
|
| 4 | + "fmt" |
| 5 | + "strings" |
4 | 6 | "sync"
|
5 | 7 |
|
6 | 8 | "golang.org/x/net/context"
|
@@ -71,13 +73,34 @@ func vulncheckRun(lintCtx *linter.Context, pass *analysis.Pass, settings *config
|
71 | 73 | return nil, err
|
72 | 74 | }
|
73 | 75 |
|
| 76 | + imports := vulncheck.ImportChains(r) |
74 | 77 | issues := make([]goanalysis.Issue, 0, len(r.Vulns))
|
75 | 78 |
|
76 |
| - for _, vuln := range r.Vulns { |
| 79 | + for idx, vuln := range r.Vulns { |
77 | 80 | issues = append(issues, goanalysis.NewIssue(&result.Issue{
|
78 |
| - Text: vuln.OSV.ID, |
| 81 | + Text: writeVulnerability(idx, vuln.OSV.ID, vuln.OSV.Details, writeImorts(imports[vuln])), |
79 | 82 | }, pass))
|
80 | 83 | }
|
81 | 84 |
|
82 | 85 | return issues, nil
|
83 | 86 | }
|
| 87 | + |
| 88 | +func writeImorts(imports []vulncheck.ImportChain) string { |
| 89 | + var s strings.Builder |
| 90 | + for _, i := range imports { |
| 91 | + indent := 0 |
| 92 | + for _, pkg := range i { |
| 93 | + s.WriteString(fmt.Sprintf("%s|_ %s", strings.Repeat(" ", indent), pkg.Name)) |
| 94 | + } |
| 95 | + } |
| 96 | + |
| 97 | + return s.String() |
| 98 | +} |
| 99 | + |
| 100 | +func writeVulnerability(idx int, id, details, imports string) string { |
| 101 | + return fmt.Sprintf(`Vulnerability #%d: %s |
| 102 | +%s |
| 103 | +%s |
| 104 | + More info: https://pkg.go.dev/vuln/%s |
| 105 | +`, idx, id, details, imports, id) |
| 106 | +} |
0 commit comments