Repository navigation
feat(sarif): Export full govulncheck call traces #5
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -190,6 +190,7 @@ func parseGovulncheck(r io.Reader, dir string, res *Result, o Options) (reachabl | |
| seen := map[string]bool{} | ||
| callSites := map[string]string{} | ||
| callLines := map[string]string{} | ||
| traces := map[string][]onlinescan.TraceFrame{} | ||
| calledMod := map[string]string{} | ||
| osvModules := map[string][]string{} | ||
| severity := map[string]string{} | ||
|
|
@@ -221,6 +222,19 @@ func parseGovulncheck(r io.Reader, dir string, res *Result, o Options) (reachabl | |
| seen[id] = true | ||
| if len(m.Finding.Trace) > 0 && m.Finding.Trace[0].Function != "" { | ||
| called[id] = true | ||
| if _, exists := traces[normID(id)]; !exists { | ||
| for _, fr := range m.Finding.Trace { | ||
|
Comment on lines
+225
to
+226
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
When govulncheck emits multiple Useful? React with 👍 / 👎. |
||
| frame := onlinescan.TraceFrame{ | ||
| Module: fr.Module, Package: fr.Package, Function: fr.Function, | ||
| FirstParty: isFirstPartyFrame(fr, res), | ||
| } | ||
| if fr.Position != nil { | ||
| frame.File = fr.Position.Filename | ||
| frame.Line = fr.Position.Line | ||
| } | ||
| traces[normID(id)] = append(traces[normID(id)], frame) | ||
| } | ||
| } | ||
|
|
||
| if calledMod[id] == "" { | ||
| for _, fr := range m.Finding.Trace { | ||
|
|
@@ -300,6 +314,18 @@ func parseGovulncheck(r io.Reader, dir string, res *Result, o Options) (reachabl | |
| } | ||
| } | ||
| } | ||
| if trace := traces[normID(id)]; len(trace) > 0 { | ||
| if res.Traces == nil { | ||
| res.Traces = map[string][]onlinescan.TraceFrame{} | ||
| } | ||
| res.Traces[normID(id)] = trace | ||
| for _, a := range aliases[id] { | ||
| nid := normID(a) | ||
| if len(res.Traces[nid]) == 0 { | ||
| res.Traces[nid] = trace | ||
| } | ||
| } | ||
| } | ||
| } else { | ||
| unreachable++ | ||
| } | ||
|
|
@@ -318,6 +344,13 @@ func parseGovulncheck(r io.Reader, dir string, res *Result, o Options) (reachabl | |
| return reachable, unreachable, nil | ||
| } | ||
|
|
||
| func isFirstPartyFrame(fr gvkFrame, res *Result) bool { | ||
| if fr.Position == nil || fr.Position.Filename == "" || fr.Module == "stdlib" { | ||
| return false | ||
| } | ||
| return !res.HaveModuleUsage || !res.Modules[fr.Module] || fr.Module == res.MainModule | ||
| } | ||
|
|
||
| func gvkExtractSeverity(osv *gvkOSV) string { | ||
| if osv == nil { | ||
| return "" | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
When a govulncheck function frame lacks a source position, this branch drops the frame entirely even though its module, package, and function were retained in
Trace. If all frames are unpositioned, SARIF falls back to the single call site or emits no flow; if only some are unpositioned, the remaining frames can also be mislabeled as the entry point or vulnerable function. Emit a message/logical-only thread-flow location for such frames rather than removing them.Useful? React with 👍 / 👎.