Skip to content

Commit ecd5c8c

Browse files
committed
Test builtins like standard library
1 parent 03d5047 commit ecd5c8c

File tree

1 file changed

+104
-0
lines changed
  • go/ql/test/library-tests/semmle/go/frameworks/StdlibTaintFlow

1 file changed

+104
-0
lines changed
Lines changed: 104 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,104 @@
1+
package main
2+
3+
// Also tested in go/ql/test/library-tests/semmle/go/dataflow/ExternalValueFlow
4+
// and go/ql/test/library-tests/semmle/go/dataflow/ExternalTaintFlow.
5+
6+
func TaintStepTest_Append1(sourceCQL interface{}) interface{} {
7+
from := sourceCQL.([]byte)
8+
var intoInterface interface{}
9+
intoInterface = append(from, "a string"...)
10+
return intoInterface
11+
}
12+
13+
func TaintStepTest_Append2(sourceCQL interface{}) interface{} {
14+
from := sourceCQL.(int)
15+
slice := []int{from}
16+
var intoInterface []int
17+
intoInterface = append(slice, 0)
18+
return intoInterface[0]
19+
}
20+
21+
func TaintStepTest_Append3(sourceCQL interface{}) interface{} {
22+
from := sourceCQL.(string)
23+
var intoInterface interface{}
24+
intoInterface = append([]byte{}, from...)
25+
return intoInterface
26+
}
27+
28+
func TaintStepTest_Append4(sourceCQL interface{}) interface{} {
29+
from := sourceCQL.(int)
30+
var intoInterface []int
31+
intoInterface = append([]int{}, 0, from, 1)
32+
return intoInterface[0]
33+
}
34+
35+
func TaintStepTest_Copy1(sourceCQL interface{}) interface{} {
36+
from := sourceCQL.(string)
37+
var intoInterface []byte
38+
copy(intoInterface, from)
39+
return intoInterface
40+
}
41+
42+
func TaintStepTest_Copy2(sourceCQL interface{}) interface{} {
43+
from := []int{sourceCQL.(int)}
44+
var intoInterface []int
45+
copy(intoInterface, from)
46+
return intoInterface[0]
47+
}
48+
49+
func TaintStepTest_Max(sourceCQL interface{}) interface{} {
50+
from := sourceCQL.(int)
51+
var intoInterface int
52+
intoInterface = max(0, 1, from, 2, 3)
53+
return intoInterface
54+
}
55+
56+
func TaintStepTest_Min(sourceCQL interface{}) interface{} {
57+
from := sourceCQL.(int)
58+
var intoInterface int
59+
intoInterface = min(0, 1, from, 2, 3)
60+
return intoInterface
61+
}
62+
63+
func RunAllTaints_Builtin() {
64+
{
65+
source := newSource(0)
66+
out := TaintStepTest_Append1(source)
67+
sink(0, out)
68+
}
69+
{
70+
source := newSource(1)
71+
out := TaintStepTest_Append2(source)
72+
sink(1, out)
73+
}
74+
{
75+
source := newSource(2)
76+
out := TaintStepTest_Append3(source)
77+
sink(2, out)
78+
}
79+
{
80+
source := newSource(3)
81+
out := TaintStepTest_Append4(source)
82+
sink(3, out)
83+
}
84+
{
85+
source := newSource(4)
86+
out := TaintStepTest_Copy1(source)
87+
sink(4, out)
88+
}
89+
{
90+
source := newSource(5)
91+
out := TaintStepTest_Copy2(source)
92+
sink(5, out)
93+
}
94+
{
95+
source := newSource(3)
96+
out := TaintStepTest_Max(source)
97+
sink(3, out)
98+
}
99+
{
100+
source := newSource(4)
101+
out := TaintStepTest_Min(source)
102+
sink(4, out)
103+
}
104+
}

0 commit comments

Comments
 (0)