Skip to content

Commit 0c44de6

Browse files
committed
internal/report: refactor fix to avoid nil pointer
Split Fix into FixText (which doesn't require a proxy client) and FixVersions (which does), and only call the FixText portion from applySuggestion in vulnreport. This avoids a possible nil pointer dereference. Change-Id: Ic57cb0738ac64ce892e62c2e16c76efb25c22147 Reviewed-on: https://go-review.googlesource.com/c/vulndb/+/562245 LUCI-TryBot-Result: Go LUCI <[email protected]> Reviewed-by: Damien Neil <[email protected]>
1 parent 48391af commit 0c44de6

File tree

2 files changed

+8
-4
lines changed

2 files changed

+8
-4
lines changed

cmd/vulnreport/suggest.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -130,5 +130,5 @@ func suggestions(ctx context.Context, c genai.Client, r *report.Report, max int)
130130
func applySuggestion(r *report.Report, s *genai.Suggestion) {
131131
r.Summary = report.Summary(s.Summary)
132132
r.Description = report.Description(s.Description)
133-
r.Fix(nil)
133+
r.FixText()
134134
}

internal/report/fix.go

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,13 @@ import (
1717
)
1818

1919
func (r *Report) Fix(pc *proxy.Client) {
20-
for _, ref := range r.References {
21-
ref.URL = fixURL(ref.URL)
22-
}
2320
for _, m := range r.Modules {
2421
m.FixVersions(pc)
2522
}
23+
r.FixText()
24+
}
25+
26+
func (r *Report) FixText() {
2627
fixLines := func(sp *string) {
2728
*sp = fixLineLength(*sp, maxLineLength)
2829
}
@@ -31,6 +32,9 @@ func (r *Report) Fix(pc *proxy.Client) {
3132
if r.CVEMetadata != nil {
3233
fixLines(&r.CVEMetadata.Description)
3334
}
35+
for _, ref := range r.References {
36+
ref.URL = fixURL(ref.URL)
37+
}
3438
}
3539

3640
// FixVersions replaces each version with its canonical form (if possible),

0 commit comments

Comments
 (0)