diff --git a/pkg/fortify/fpr_to_sarif.go b/pkg/fortify/fpr_to_sarif.go index 4758d879d..892840978 100644 --- a/pkg/fortify/fpr_to_sarif.go +++ b/pkg/fortify/fpr_to_sarif.go @@ -648,25 +648,29 @@ func Parse(sys System, project *models.Project, projectVersion *models.ProjectVe default: snippetTarget = fvdl.Vulnerabilities.Vulnerability[i].AnalysisInfo.Trace[k].Primary.Entry[l].Node.Action.ActionData } - physLocationSnippetLines := strings.Split(threadFlowLocation.Location.PhysicalLocation.ContextRegion.Snippet.Text, "\n") - snippetText := "" - for j := 0; j < len(physLocationSnippetLines); j++ { - if strings.Contains(physLocationSnippetLines[j], snippetTarget) { - snippetText = physLocationSnippetLines[j] - break + if threadFlowLocation.Location.PhysicalLocation.ContextRegion.Snippet != nil { + physLocationSnippetLines := strings.Split(threadFlowLocation.Location.PhysicalLocation.ContextRegion.Snippet.Text, "\n") + snippetText := "" + for j := 0; j < len(physLocationSnippetLines); j++ { + if strings.Contains(physLocationSnippetLines[j], snippetTarget) { + snippetText = physLocationSnippetLines[j] + break + } } + snippetSarif := new(format.SnippetSarif) + if snippetText != "" { + snippetSarif.Text = snippetText + } else { + snippetSarif.Text = threadFlowLocation.Location.PhysicalLocation.ContextRegion.Snippet.Text + } + threadFlowLocation.Location.PhysicalLocation.Region.Snippet = snippetSarif } - snippetSarif := new(format.SnippetSarif) - if snippetText != "" { - snippetSarif.Text = snippetText - } else { - snippetSarif.Text = threadFlowLocation.Location.PhysicalLocation.ContextRegion.Snippet.Text - } - threadFlowLocation.Location.PhysicalLocation.Region.Snippet = snippetSarif } else { - snippetSarif := new(format.SnippetSarif) - snippetSarif.Text = threadFlowLocation.Location.PhysicalLocation.ContextRegion.Snippet.Text - threadFlowLocation.Location.PhysicalLocation.Region.Snippet = snippetSarif + if threadFlowLocation.Location.PhysicalLocation.ContextRegion.Snippet != nil { + snippetSarif := new(format.SnippetSarif) + snippetSarif.Text = threadFlowLocation.Location.PhysicalLocation.ContextRegion.Snippet.Text + threadFlowLocation.Location.PhysicalLocation.Region.Snippet = snippetSarif + } } location = *threadFlowLocation.Location //set Kinds diff --git a/pkg/fortify/fpr_to_sarif_test.go b/pkg/fortify/fpr_to_sarif_test.go index 96e0129b8..387f04d6e 100644 --- a/pkg/fortify/fpr_to_sarif_test.go +++ b/pkg/fortify/fpr_to_sarif_test.go @@ -60,6 +60,9 @@ func TestParse(t *testing.T) { + + + @@ -86,6 +89,7 @@ func TestParse(t *testing.T) { + Dummy action @@ -292,6 +296,7 @@ If you are concerned about leaking system data via NFC on an Android device, you 5 1 5 + CWE ID 111