From 41ea43177968b25cef193bee8652853c7dcc7d71 Mon Sep 17 00:00:00 2001 From: K Date: Mon, 4 Jan 2021 16:38:41 -0800 Subject: [PATCH] Fix for SARIF output when Issue.Line contains a range --- output/sarif_format.go | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/output/sarif_format.go b/output/sarif_format.go index 4a29ea8..7070233 100644 --- a/output/sarif_format.go +++ b/output/sarif_format.go @@ -35,6 +35,7 @@ type sarifArtifactLocation struct { type sarifRegion struct { StartLine uint64 `json:"startLine"` + EndLine uint64 `json:"endLine"` StartColumn uint64 `json:"startColumn"` EndColumn uint64 `json:"endColumn"` } @@ -114,10 +115,19 @@ func buildSarifRule(issue *gosec.Issue) *sarifRule { func buildSarifLocation(issue *gosec.Issue, rootPaths []string) (*sarifLocation, error) { var filePath string - line, err := strconv.ParseUint(issue.Line, 10, 64) + lines := strings.Split(issue.Line, "-") + startLine, err := strconv.ParseUint(lines[0], 10, 64) if err != nil { return nil, err } + endLine := startLine + if len(lines) > 1 { + endLine, err = strconv.ParseUint(lines[1], 10, 64) + if err != nil { + return nil, err + } + } + col, err := strconv.ParseUint(issue.Col, 10, 64) if err != nil { return nil, err @@ -135,7 +145,8 @@ func buildSarifLocation(issue *gosec.Issue, rootPaths []string) (*sarifLocation, URI: filePath, }, Region: &sarifRegion{ - StartLine: line, + StartLine: startLine, + EndLine: endLine, StartColumn: col, EndColumn: col, },