Skip to content

Commit

Permalink
internal/vulncheck: remove file set computation
Browse files Browse the repository at this point in the history
Source function is internal so it can make certain assumptions about how
it is called. This assumptions (now documented) allow us to avoid
computing and validating file sets, resulting in simplified code.

Fixes golang/go#59729

Change-Id: Iea7e5c91d51a8243451f13a3d13fa0672cca77cd
Reviewed-on: https://go-review.googlesource.com/c/vuln/+/532215
Reviewed-by: Maceo Thompson <[email protected]>
Run-TryBot: Zvonimir Pavlinovic <[email protected]>
LUCI-TryBot-Result: Go LUCI <[email protected]>
TryBot-Result: Gopher Robot <[email protected]>
  • Loading branch information
zpavlinovic committed Oct 30, 2023
1 parent be8c702 commit 0f3617a
Showing 1 changed file with 3 additions and 18 deletions.
21 changes: 3 additions & 18 deletions internal/vulncheck/source.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@ package vulncheck

import (
"context"
"fmt"
"go/token"
"sync"

"golang.org/x/tools/go/callgraph"
Expand All @@ -27,26 +25,13 @@ import (
// some known vulnerabilities.
//
// 3) A CallGraph leading to the use of a known vulnerable function or method.
//
// Assumes that pkgs are non-empty and belong to the same program.
func Source(ctx context.Context, handler govulncheck.Handler, pkgs []*packages.Package, cfg *govulncheck.Config, client *client.Client, graph *PackageGraph) (_ *Result, err error) {
// buildSSA builds a whole program that assumes all packages use the same FileSet.
// Check all packages in pkgs are using the same FileSet.
// TODO(https://go.dev/issue/59729): take FileSet out of Package and
// let Source take a single FileSet. That will make the enforcement
// clearer from the API level.
var fset *token.FileSet
for _, p := range pkgs {
if fset == nil {
fset = p.Fset
} else {
if fset != p.Fset {
return nil, fmt.Errorf("[]*Package must have created with the same FileSet")
}
}
}

ctx, cancel := context.WithCancel(ctx)
defer cancel()

fset := pkgs[0].Fset
// If we are building the callgraph, build ssa and the callgraph in parallel
// with fetching vulnerabilities. If the vulns set is empty, return without
// waiting for SSA construction or callgraph to finish.
Expand Down

0 comments on commit 0f3617a

Please sign in to comment.