diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index 49f6f4a1..042464d9 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -11,7 +11,7 @@ on: branches: [master] env: - GO_VERSION: "1.14" + GO_VERSION: "1.18" jobs: lint: @@ -47,13 +47,13 @@ jobs: - name: Check for license headers if: ${{ always() }} run: | - go get -u github.com/google/addlicense + go install github.com/google/addlicense@latest addlicense -check cmd internal pkg - name: Run staticcheck if: ${{ always() }} run: | - go install honnef.co/go/tools/cmd/staticcheck + go install honnef.co/go/tools/cmd/staticcheck@v0.3.3 staticcheck ./... - name: Check YAML diff --git a/go.mod b/go.mod index ae8ac5f8..3ec1c802 100644 --- a/go.mod +++ b/go.mod @@ -4,6 +4,6 @@ go 1.14 require ( github.com/google/go-cmp v0.5.2 - golang.org/x/tools v0.0.0-20200416214402-fc959738d646 + golang.org/x/tools v0.1.12 sigs.k8s.io/yaml v1.2.0 ) diff --git a/go.sum b/go.sum index 269efb6a..90bed9be 100644 --- a/go.sum +++ b/go.sum @@ -2,24 +2,32 @@ github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/google/go-cmp v0.5.2 h1:X2ev0eStA3AbceY54o37/0PQ/UWqKEiiO2dKL5OPaFM= github.com/google/go-cmp v0.5.2/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= -github.com/yuin/goldmark v1.1.27/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74= +github.com/yuin/goldmark v1.4.13/go.mod h1:6yULJ656Px+3vBD8DxQVa3kxgyrAnzto9xy5taEt/CY= golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w= -golang.org/x/crypto v0.0.0-20191011191535-87dc89f01550/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI= -golang.org/x/mod v0.2.0 h1:KU7oHjnv3XNWfa5COkzUifxZmxp1TyI7ImMXqFxLwvQ= -golang.org/x/mod v0.2.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA= -golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg= +golang.org/x/crypto v0.0.0-20210921155107-089bfa567519/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc= +golang.org/x/mod v0.6.0-dev.0.20220419223038-86c51ed26bb4 h1:6zppjxzCulZykYSLyVDYbneBfbaBIQPYMevg0bEwv2s= +golang.org/x/mod v0.6.0-dev.0.20220419223038-86c51ed26bb4/go.mod h1:jJ57K6gSWd91VN4djpZkiMVwK6gcyfeH4XE8wZrZaV4= golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= -golang.org/x/net v0.0.0-20200226121028-0de0cce0169b/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= +golang.org/x/net v0.0.0-20210226172049-e18ecbb05110/go.mod h1:m0MpNAwzfU5UDzcl9v0D8zg8gWTRqZa9RBIspLL5mdg= +golang.org/x/net v0.0.0-20220722155237-a158d28d115b/go.mod h1:XRhObCWvk6IyKnWLug+ECip1KBveYUHfp+8e9klMJ9c= golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= -golang.org/x/sync v0.0.0-20190911185100-cd5d95a43a6e/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= +golang.org/x/sync v0.0.0-20220722155255-886fb9371eb4/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= -golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20210615035016-665e8c7367d1/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.0.0-20220520151302-bc2c85ada10a/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.0.0-20220722155257-8c9f86f7a55f h1:v4INt8xihDGvnrfjMDVXGxw9wrfxYyCjk0KbXjhR55s= +golang.org/x/sys v0.0.0-20220722155257-8c9f86f7a55f/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo= +golang.org/x/term v0.0.0-20210927222741-03fcf44c2211/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8= golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= +golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= +golang.org/x/text v0.3.7/go.mod h1:u+2+/6zg+i71rQMx5EYifcz6MCKuco9NR6JIITiCfzQ= +golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= golang.org/x/tools v0.0.0-20191119224855-298f0cb1881e/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= -golang.org/x/tools v0.0.0-20200416214402-fc959738d646 h1:7CEkhBsBejkW845gR1AmglqMfc1yGzn42FBmtM4jxyM= -golang.org/x/tools v0.0.0-20200416214402-fc959738d646/go.mod h1:EkVYQZoAsY45+roYkvgYkIh4xh/qjgUK9TdY2XT94GE= +golang.org/x/tools v0.1.12 h1:VveCTK38A2rkS8ZqFY25HIDFscX5X9OoEhJd3quQmXU= +golang.org/x/tools v0.1.12/go.mod h1:hNGJHUnrk76NpqgfD5Aqm5Crs+Hm0VOH/i9J2+nxYbc= golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= -golang.org/x/xerrors v0.0.0-20191011141410-1b5146add898/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543 h1:E7g+9GITq07hpfrRu66IVDexMakfv52eLZ2CXBWiKr4= golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM= diff --git a/internal/pkg/debug/render/render_test.go b/internal/pkg/debug/render/render_test.go index a4fe82b6..6688edaf 100644 --- a/internal/pkg/debug/render/render_test.go +++ b/internal/pkg/debug/render/render_test.go @@ -26,6 +26,7 @@ import ( "testing" "github.com/google/go-cmp/cmp" + "github.com/google/go-flow-levee/internal/pkg/utils" "golang.org/x/tools/go/ssa" "golang.org/x/tools/go/ssa/ssautil" ) @@ -54,6 +55,11 @@ func testGoldenFiles(t *testing.T, fn func(f *ssa.Function) string, fnName, ext } want := string(bytes) + // Replace interface{} in golden files if necessary. + if utils.DefaultEmptyInterface != "interface{}" { + want = strings.ReplaceAll(want, "interface{}", utils.DefaultEmptyInterface) + } + got := fn(f) if diff := cmp.Diff(want, got); diff != "" { diff --git a/internal/pkg/earpointer/analysis_test.go b/internal/pkg/earpointer/analysis_test.go index b2e8ea93..7faeabc5 100644 --- a/internal/pkg/earpointer/analysis_test.go +++ b/internal/pkg/earpointer/analysis_test.go @@ -1201,11 +1201,11 @@ func TestMethodInvoke(t *testing.T) { // Note that in "**T2", the first "*" is the synthesized ValueOf operator, // and "*T2" is the receiver type. want := concat(map[string]string{ - "{**T2:f.arg0}": "[T1->*T1:f.arg0]", + "{**T2:f.arg0}": "[T1->g.t0]", "{*T1:f.arg0,*T2:f.t0,g.t0}": "[]", "{*T1:f.x,*T2:f.x,g.x}": "[]", "{*T2:f.arg0}": "--> **T2:f.arg0", - "{*g.x2}": "[T1->*T1:f.arg0]", + "{*g.x2}": "[T1->g.t0]", "{g.x2}": "--> *g.x2", }) if got := state.String(); got != want { diff --git a/internal/pkg/levee/testdata/src/levee_analysistest/example/tests/position/tests.go b/internal/pkg/levee/testdata/src/levee_analysistest/example/tests/position/tests.go index 3484e985..48cc6f37 100644 --- a/internal/pkg/levee/testdata/src/levee_analysistest/example/tests/position/tests.go +++ b/internal/pkg/levee/testdata/src/levee_analysistest/example/tests/position/tests.go @@ -33,13 +33,13 @@ func TestSourcePointerExtract() { func TestEmbeddedSourceFieldAddr() { es := EmbedsSource{} d := es.Data - core.Sink(d) // want "a source has reached a sink\n source: .*tests.go:34:2" + core.Sink(d) // want "a source has reached a sink\n source: .*tests.go:35:7" } // In order for the SSA to contain a Field, the EmbedsSource instance's fields must not be addressable. // One way to do this is to create a literal and to access the field directly, as part of the same expression. func TestEmbeddedSourceField() { - core.Sink(EmbedsSource{}.Data) // want "a source has reached a sink\n source: .*tests.go:42:24" + core.Sink(EmbedsSource{}.Data) // want "a source has reached a sink\n source: .*tests.go:42:12" } type EmbedsSource struct { diff --git a/internal/pkg/propagation/summary/summaries.go b/internal/pkg/propagation/summary/summaries.go index 8b2597d0..c1cc8139 100644 --- a/internal/pkg/propagation/summary/summaries.go +++ b/internal/pkg/propagation/summary/summaries.go @@ -19,6 +19,12 @@ // arguments/return values should also be tainted". package summary +import ( + "fmt" + + "github.com/google/go-flow-levee/internal/pkg/utils" +) + const ( first = 1 << iota second @@ -737,7 +743,8 @@ var InterfaceFuncSummaries = map[funcKey]Summary{ IfTainted: first, TaintedRets: []int{0}, }, - {"Value", "(interface{})(interface{})"}: { + // Either (any)(any) or (interface{})(interface{}) + {"Value", fmt.Sprintf("(%s)(%s)", utils.DefaultEmptyInterface, utils.DefaultEmptyInterface)}: { IfTainted: first, TaintedRets: []int{0}, }, diff --git a/internal/pkg/utils/utils.go b/internal/pkg/utils/utils.go index a0427986..deaafb11 100644 --- a/internal/pkg/utils/utils.go +++ b/internal/pkg/utils/utils.go @@ -81,3 +81,7 @@ func DecomposeFunction(f *ssa.Function) (path, recv, name string) { } return } + +// EmptyInterfaceString is the string rendering of an empty interface, interface{}. +// Changes based on the go version. +var DefaultEmptyInterface = "interface{}" diff --git a/internal/pkg/utils/utils_go118.go b/internal/pkg/utils/utils_go118.go new file mode 100644 index 00000000..427adba0 --- /dev/null +++ b/internal/pkg/utils/utils_go118.go @@ -0,0 +1,23 @@ +// Copyright 2022 Google LLC +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// https://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +//go:build go1.18 +// +build go1.18 + +package utils + +func init() { + // After 1.18 default rendering of interface{} is any. + DefaultEmptyInterface = "any" +}