Skip to content

Commit d9848fe

Browse files
committed
Add more tests for variadic functions
1 parent 8044fb2 commit d9848fe

File tree

1 file changed

+29
-6
lines changed
  • ql/test/library-tests/semmle/go/dataflow/VarArgs

1 file changed

+29
-6
lines changed

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

Lines changed: 29 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,17 +11,40 @@ type A struct {
1111
f string
1212
}
1313

14-
func functionWithVarArgsOfStructsParameter(s ...A) {
15-
sink(s[0].f) // $ MISSING: taintflow dataflow
14+
func functionWithSliceParameter(s []string) string {
15+
return s[1]
16+
}
17+
18+
func functionWithVarArgsParameter(s ...string) string {
19+
return s[1]
20+
}
21+
22+
func functionWithSliceOfStructsParameter(s []A) string {
23+
return s[1].f
24+
}
25+
26+
func functionWithVarArgsOfStructsParameter(s ...A) string {
27+
return s[1].f
1628
}
1729

1830
func main() {
1931
stringSlice := []string{source()}
2032
sink(stringSlice[0]) // $ taintflow dataflow
2133

22-
arrayOfStructs := []A{{f: source()}}
23-
sink(arrayOfStructs[0].f) // $ taintflow dataflow
34+
s0 := ""
35+
s1 := source()
36+
sSlice := []string{s0, s1}
37+
sink(functionWithSliceParameter(sSlice)) // $ taintflow dataflow
38+
sink(functionWithVarArgsParameter(sSlice...)) // $ taintflow dataflow
39+
sink(functionWithVarArgsParameter(s0, s1)) // $ MISSING: taintflow dataflow
40+
41+
sliceOfStructs := []A{{f: source()}}
42+
sink(sliceOfStructs[0].f) // $ taintflow dataflow
2443

25-
a := A{f: source()}
26-
functionWithVarArgsOfStructsParameter(a)
44+
a0 := A{f: ""}
45+
a1 := A{f: source()}
46+
aSlice := []A{a0, a1}
47+
sink(functionWithSliceOfStructsParameter(aSlice)) // $ taintflow dataflow
48+
sink(functionWithVarArgsOfStructsParameter(aSlice...)) // $ taintflow dataflow
49+
sink(functionWithVarArgsOfStructsParameter(a0, a1)) // $ MISSING: taintflow dataflow
2750
}

0 commit comments

Comments
 (0)