Skip to content

Commit d6c8767

Browse files
committed
Test flow out of varargs parameter in function model
1 parent ec81539 commit d6c8767

File tree

4 files changed

+22
-6
lines changed

4 files changed

+22
-6
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.25
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: 15 additions & 5 deletions
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() {
@@ -21,10 +21,17 @@ func main() {
2121
s0 := ""
2222
s1 := source()
2323
sSlice := []string{s0, s1}
24-
sink(test.FunctionWithParameter(sSlice[1])) // $ hasValueFlow="call to FunctionWithParameter"
25-
sink(test.FunctionWithSliceParameter(sSlice)) // $ hasTaintFlow="call to FunctionWithSliceParameter" MISSING: hasValueFlow="call to FunctionWithSliceParameter"
26-
sink(test.FunctionWithVarArgsParameter(sSlice...)) // $ hasTaintFlow="call to FunctionWithVarArgsParameter" MISSING: hasValueFlow="call to FunctionWithVarArgsParameter"
27-
sink(test.FunctionWithVarArgsParameter(s0, s1)) // $ MISSING: hasValueFlow="call to FunctionWithVarArgsParameter"
24+
sink(test.FunctionWithParameter(sSlice[1])) // $ hasValueFlow="call to FunctionWithParameter"
25+
sink(test.FunctionWithSliceParameter(sSlice)) // $ hasTaintFlow="call to FunctionWithSliceParameter" MISSING: hasValueFlow="call to FunctionWithSliceParameter"
26+
sink(test.FunctionWithVarArgsParameter(sSlice...)) // $ hasTaintFlow="call to FunctionWithVarArgsParameter" MISSING: hasValueFlow="call to FunctionWithVarArgsParameter"
27+
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.
28+
sink(test.FunctionWithVarArgsParameter(s0, s1)) // $ hasValueFlow="call to FunctionWithVarArgsParameter"
29+
30+
var out1 *string
31+
var out2 *string
32+
test.FunctionWithVarArgsOutParameter(source(), out1, out2)
33+
sink(out1) // $ hasValueFlow="out1"
34+
sink(out2) // $ hasValueFlow="out2"
2835

2936
sliceOfStructs := []test.A{{Field: source()}}
3037
sink(sliceOfStructs[0].Field) // $ hasValueFlow="selection of Field"
@@ -37,3 +44,6 @@ func main() {
3744
sink(test.FunctionWithVarArgsOfStructsParameter(aSlice...)) // $ MISSING: hasValueFlow="call to FunctionWithVarArgsOfStructsParameter"
3845
sink(test.FunctionWithVarArgsOfStructsParameter(a0, a1)) // $ MISSING: hasValueFlow="call to FunctionWithVarArgsOfStructsParameter"
3946
}
47+
48+
func randomFunctionWithMoreThanOneParameter(i1, i2, i3, i4, i5 int) {
49+
}

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

Lines changed: 3 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)