Skip to content

Commit 96c8af8

Browse files
committed
Test flow out of varargs param with function models
1 parent 1612a7a commit 96c8af8

File tree

4 files changed

+13
-2
lines changed

4 files changed

+13
-2
lines changed

go/ql/test/library-tests/semmle/go/dataflow/VarArgsWithFunctionModels/Flows.ql

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,9 @@ class SummaryModelTest extends DataFlow::FunctionModel {
1919
this.hasQualifiedName("github.com/nonexistent/test", "FunctionWithVarArgsParameter") and
2020
(inp.isParameter(_) and outp.isResult())
2121
or
22+
this.hasQualifiedName("github.com/nonexistent/test", "FunctionWithVarArgsOutParameter") and
23+
(inp.isParameter(0) and outp.isParameter(any(int i | i >= 1)))
24+
or
2225
this.hasQualifiedName("github.com/nonexistent/test", "FunctionWithSliceOfStructsParameter") and
2326
(inp.isParameter(0) and outp.isResult())
2427
or
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
module semmle.go.Packages
22

3-
go 1.17
3+
go 1.23
44

55
require github.com/nonexistent/test v0.0.0-20200203000000-0000000000000

go/ql/test/library-tests/semmle/go/dataflow/VarArgsWithFunctionModels/main.go

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ func source() string {
88
return "untrusted data"
99
}
1010

11-
func sink(string) {
11+
func sink(any) {
1212
}
1313

1414
func main() {
@@ -27,6 +27,12 @@ func main() {
2727
randomFunctionWithMoreThanOneParameter(1, 2, 3, 4, 5) // This is needed to make the next line pass, because we need to have seen a call to a function with at least 2 parameters for ParameterInput to exist with index 1.
2828
sink(test.FunctionWithVarArgsParameter(s0, s1)) // $ hasValueFlow="call to FunctionWithVarArgsParameter"
2929

30+
var out1 *string
31+
var out2 *string
32+
test.FunctionWithVarArgsOutParameter(source(), out1, out2)
33+
sink(out1) // $ hasValueFlow="out1"
34+
sink(out2) // $ hasValueFlow="out2"
35+
3036
sliceOfStructs := []test.A{{Field: source()}}
3137
sink(sliceOfStructs[0].Field) // $ hasValueFlow="selection of Field"
3238

go/ql/test/library-tests/semmle/go/dataflow/VarArgsWithFunctionModels/vendor/github.com/nonexistent/test/stub.go

Lines changed: 2 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)