Skip to content

Commit

Permalink
vulncheck: add support for generics
Browse files Browse the repository at this point in the history
Make ssa instantiate generics.

Fixes golang/go#57174

Change-Id: I2d2e28a48e3a64df3d4d415b4629fe3e0a1ba28d
Reviewed-on: https://go-review.googlesource.com/c/vuln/+/456436
Reviewed-by: Fnu Harshavardhana <[email protected]>
Run-TryBot: Zvonimir Pavlinovic <[email protected]>
TryBot-Result: Gopher Robot <[email protected]>
Reviewed-by: Jonathan Amsterdam <[email protected]>
  • Loading branch information
sayjun0505 committed Dec 12, 2022
1 parent 8229fe2 commit dc6157d
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 1 deletion.
52 changes: 52 additions & 0 deletions vulncheck/source_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -848,3 +848,55 @@ func TestRecursion(t *testing.T) {
t.Errorf("want 3 functions (X, y, Vuln) in vulnerability graph; got %v", l)
}
}

func TestIssue57174(t *testing.T) {
e := packagestest.Export(t, packagestest.Modules, []packagestest.Module{
{
Name: "golang.org/entry",
Files: map[string]interface{}{
"x/x.go": `
package x
import "golang.org/bmod/bvuln"
func P(d [][3]int) {
p(d)
}
func p[E interface{ [3]int | [4]int }](d []E) {
c := d[0]
if c[0] > 0 {
bvuln.Vuln()
}
}
`,
},
},
{
Name: "golang.org/[email protected]",
Files: map[string]interface{}{"bvuln/bvuln.go": `
package bvuln
func Vuln() {}
`},
},
})
defer e.Cleanup()

// Load x as entry package.
pkgs, err := test.LoadPackages(e, path.Join(e.Temp(), "entry/x"))
if err != nil {
t.Fatal(err)
}
if len(pkgs) != 1 {
t.Fatal("failed to load x test package")
}

cfg := &Config{
Client: testClient,
}
_, err = Source(context.Background(), Convert(pkgs), cfg)
if err != nil {
t.Fatal(err)
}
}
3 changes: 2 additions & 1 deletion vulncheck/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@ import (
// the ssa program encapsulating the packages and top level
// ssa packages corresponding to pkgs.
func buildSSA(pkgs []*Package, fset *token.FileSet) (*ssa.Program, []*ssa.Package) {
prog := ssa.NewProgram(fset, ssa.BuilderMode(0))
// TODO(#57221): what about entry functions that are generics?
prog := ssa.NewProgram(fset, ssa.InstantiateGenerics)

imports := make(map[*Package]*ssa.Package)
var createImports func([]*Package)
Expand Down

0 comments on commit dc6157d

Please sign in to comment.