Skip to content

Commit 8044fb2

Browse files
committed
Add more flow tests for external flow
1 parent 63d997f commit 8044fb2

File tree

7 files changed

+75
-46
lines changed

7 files changed

+75
-46
lines changed

ql/test/library-tests/semmle/go/dataflow/ExternalFlow/completetest.ql

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,15 @@ class SummaryModelTest extends SummaryModelCsv {
1414
row =
1515
[
1616
//`namespace; type; subtypes; name; signature; ext; input; output; kind`
17+
"github.com/nonexistent/test;T;false;StepArgRes;;;Argument[0];ReturnValue;taint",
18+
"github.com/nonexistent/test;T;false;StepArgRes1;;;Argument[0];ReturnValue[1];taint",
19+
"github.com/nonexistent/test;T;false;StepArgArg;;;Argument[0];Argument[1];taint",
20+
"github.com/nonexistent/test;T;false;StepArgQual;;;Argument[0];Argument[-1];taint",
21+
"github.com/nonexistent/test;T;false;StepQualRes;;;Argument[-1];ReturnValue;taint",
22+
"github.com/nonexistent/test;T;false;StepQualArg;;;Argument[-1];Argument[0];taint",
23+
"github.com/nonexistent/test;;false;StepArgResNoQual;;;Argument[0];ReturnValue;taint",
1724
"github.com/nonexistent/test;;false;StepArgResContent;;;Argument[0];ArrayElement of ReturnValue;taint",
18-
"github.com/nonexistent/test;T;false;StepArgRes;;;Argument[0];ReturnValue;taint"
25+
"github.com/nonexistent/test;;false;StepArgContentRes;;;ArrayElement of Argument[0];ReturnValue;taint",
1926
]
2027
}
2128
}
Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,13 @@
11
invalidModelRow
22
#select
3-
| test.go:40:10:40:12 | arg | qltest |
4-
| test.go:55:10:55:14 | taint | qltest |
5-
| test.go:66:10:66:17 | index expression | qltest |
6-
| test.go:78:10:78:17 | index expression | qltest |
3+
| test.go:43:10:43:12 | arg | qltest |
4+
| test.go:57:10:57:15 | taint1 | qltest |
5+
| test.go:60:10:60:15 | taint2 | qltest |
6+
| test.go:64:10:64:15 | taint3 | qltest |
7+
| test.go:68:10:68:15 | taint4 | qltest |
8+
| test.go:71:10:71:15 | taint5 | qltest |
9+
| test.go:75:10:75:15 | taint6 | qltest |
10+
| test.go:78:10:78:15 | taint7 | qltest |
11+
| test.go:81:10:81:18 | index expression | qltest |
12+
| test.go:85:10:85:15 | taint9 | qltest |
13+
| test.go:89:10:89:17 | index expression | qltest |
Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,12 @@
11
invalidModelRow
22
#select
3-
| test.go:11:6:11:8 | definition of arg | qltest-arg |
4-
| test.go:28:6:28:6 | definition of a | qltest-arg |
5-
| test.go:31:8:31:15 | call to Src1 | qltest |
6-
| test.go:32:8:32:15 | call to Src2 | qltest |
7-
| test.go:32:8:32:15 | call to Src2 | qltest-w-subtypes |
8-
| test.go:33:8:33:16 | call to Src2 | qltest-w-subtypes |
9-
| test.go:34:2:34:21 | ... = ...[0] | qltest |
10-
| test.go:34:2:34:21 | ... = ...[1] | qltest-w-subtypes |
11-
| test.go:35:2:35:22 | ... = ...[1] | qltest-w-subtypes |
12-
| test.go:51:9:51:16 | call to Src1 | qltest |
13-
| test.go:62:9:62:16 | call to Src1 | qltest |
14-
| test.go:73:9:73:16 | call to Src1 | qltest |
3+
| test.go:12:6:12:8 | definition of arg | qltest-arg |
4+
| test.go:31:6:31:6 | definition of a | qltest-arg |
5+
| test.go:34:8:34:15 | call to Src1 | qltest |
6+
| test.go:35:8:35:15 | call to Src2 | qltest |
7+
| test.go:35:8:35:15 | call to Src2 | qltest-w-subtypes |
8+
| test.go:36:8:36:16 | call to Src2 | qltest-w-subtypes |
9+
| test.go:37:2:37:21 | ... = ...[0] | qltest |
10+
| test.go:37:2:37:21 | ... = ...[1] | qltest-w-subtypes |
11+
| test.go:38:2:38:22 | ... = ...[1] | qltest-w-subtypes |
12+
| test.go:54:9:54:16 | call to Src1 | qltest |
Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,16 @@
11
invalidModelRow
22
#select
3-
| test.go:16:23:16:25 | arg | test.go:16:10:16:26 | call to StepArgRes |
4-
| test.go:17:27:17:29 | arg | test.go:17:2:17:30 | ... = ...[1] |
5-
| test.go:18:15:18:17 | arg | test.go:12:6:12:9 | definition of arg1 |
6-
| test.go:19:16:19:18 | arg | test.go:13:6:13:6 | definition of t |
7-
| test.go:20:10:20:10 | t | test.go:20:10:20:24 | call to StepQualRes |
8-
| test.go:21:2:21:2 | t | test.go:11:6:11:8 | definition of arg |
9-
| test.go:22:32:22:34 | arg | test.go:22:10:22:35 | call to StepArgResNoQual |
10-
| test.go:53:24:53:26 | src | test.go:53:11:53:27 | call to StepArgRes |
3+
| test.go:19:23:19:25 | arg | test.go:19:10:19:26 | call to StepArgRes |
4+
| test.go:20:27:20:29 | arg | test.go:20:2:20:30 | ... = ...[1] |
5+
| test.go:21:15:21:17 | arg | test.go:13:6:13:9 | definition of arg1 |
6+
| test.go:22:16:22:18 | arg | test.go:15:6:15:6 | definition of t |
7+
| test.go:23:10:23:10 | t | test.go:23:10:23:24 | call to StepQualRes |
8+
| test.go:24:2:24:2 | t | test.go:12:6:12:8 | definition of arg |
9+
| test.go:25:32:25:34 | arg | test.go:25:10:25:35 | call to StepArgResNoQual |
10+
| test.go:56:25:56:27 | src | test.go:56:12:56:28 | call to StepArgRes |
11+
| test.go:59:29:59:31 | src | test.go:59:2:59:32 | ... := ...[1] |
12+
| test.go:63:15:63:17 | src | test.go:62:6:62:11 | definition of taint3 |
13+
| test.go:67:21:67:23 | src | test.go:66:6:66:11 | definition of taint4 |
14+
| test.go:70:13:70:25 | type assertion | test.go:70:12:70:40 | call to StepQualRes |
15+
| test.go:74:3:74:15 | type assertion | test.go:73:6:73:11 | definition of taint6 |
16+
| test.go:77:34:77:36 | src | test.go:77:12:77:37 | call to StepArgResNoQual |

ql/test/library-tests/semmle/go/dataflow/ExternalFlow/steps.ql

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ class SummaryModelTest extends SummaryModelCsv {
1616
"github.com/nonexistent/test;T;false;StepQualRes;;;Argument[-1];ReturnValue;taint",
1717
"github.com/nonexistent/test;T;false;StepQualArg;;;Argument[-1];Argument[0];taint",
1818
"github.com/nonexistent/test;;false;StepArgResNoQual;;;Argument[0];ReturnValue;taint",
19-
"github.com/nonexistent/test;;false;StepArgResContent;;;Argument[0];Element of ReturnValue;taint",
19+
"github.com/nonexistent/test;;false;StepArgResContent;;;Argument[0];ArrayElement of ReturnValue;taint",
2020
"github.com/nonexistent/test;;false;StepArgContentRes;;;ArrayElement of Argument[0];ReturnValue;taint"
2121
]
2222
}
Lines changed: 30 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,20 @@
11
package main
22

33
import (
4-
"github.com/nonexistent/test"
54
"io"
5+
6+
"github.com/nonexistent/test"
67
)
78

89
func use(args ...interface{}) {}
910

1011
func main() {
1112
var arg interface{}
1213
var arg1 interface{}
14+
var array []interface{}
1315
var t *test.T
1416
var taint interface{}
17+
var taintSlice []interface{}
1518

1619
taint = t.StepArgRes(arg)
1720
_, taint = t.StepArgRes1(arg)
@@ -20,8 +23,8 @@ func main() {
2023
taint = t.StepQualRes()
2124
t.StepQualArg(arg)
2225
taint = test.StepArgResNoQual(arg)
23-
taint = test.StepArgResContent(arg)
24-
taint = test.StepArgContentRes(arg)
26+
taintSlice = test.StepArgResContent(arg)
27+
taint = test.StepArgContentRes(array)
2528

2629
var src interface{}
2730
var src1 interface{}
@@ -40,7 +43,7 @@ func main() {
4043
b.Sink1(arg)
4144
b.SinkMethod().(io.Writer).Write(arg.([]byte))
4245

43-
use(arg, arg1, t, taint, src, src1)
46+
use(arg, arg1, t, taint, taintSlice, src, src1)
4447
}
4548

4649
func simpleflow() {
@@ -50,30 +53,38 @@ func simpleflow() {
5053

5154
src := a.Src1()
5255

53-
taint := t.StepArgRes(src)
56+
taint1 := t.StepArgRes(src)
57+
b.Sink1(taint1) // $ hasTaintFlow="taint1"
5458

55-
b.Sink1(taint) // $ hasTaintFlow="taint"
56-
}
59+
_, taint2 := t.StepArgRes1(src)
60+
b.Sink1(taint2) // $ hasTaintFlow="taint2"
5761

58-
func simpleflow1() {
59-
var a test.A
60-
var b test.B
62+
var taint3 interface{}
63+
t.StepArgArg(src, taint3)
64+
b.Sink1(taint3) // $ hasTaintFlow="taint3"
6165

62-
src := a.Src1()
66+
var taint4 test.T
67+
taint4.StepArgQual(src)
68+
b.Sink1(taint4) // $ hasTaintFlow="taint4"
6369

64-
taint := test.StepArgResContent(src)
70+
taint5 := (src.(*test.T)).StepQualRes()
71+
b.Sink1(taint5) // $ hasTaintFlow="taint5"
6572

66-
b.Sink1(taint[0]) // $ hasTaintFlow="index expression"
67-
}
73+
var taint6 interface{}
74+
(src.(*test.T)).StepQualArg(taint6)
75+
b.Sink1(taint6) // $ hasTaintFlow="taint6"
6876

69-
func contentflow() {
70-
var a test.A
71-
var b test.B
77+
taint7 := test.StepArgResNoQual(src)
78+
b.Sink1(taint7) // $ hasTaintFlow="taint7"
7279

73-
src := a.Src1()
80+
taint8 := test.StepArgResContent(src)
81+
b.Sink1(taint8[0]) // $ hasTaintFlow="index expression"
82+
83+
srcArray := []interface{}{nil, src}
84+
taint9 := test.StepArgContentRes(srcArray)
85+
b.Sink1(taint9) // $ hasTaintFlow="taint9"
7486

7587
slice := make([]interface{}, 0)
7688
slice = append(slice, src)
77-
7889
b.Sink1(slice[0]) // $ hasTaintFlow="index expression"
7990
}

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

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)