Skip to content

Commit 3c07cae

Browse files
committed
C#: Add test for transitive capture calls.
1 parent 70c2cc5 commit 3c07cae

File tree

7 files changed

+160
-4
lines changed

7 files changed

+160
-4
lines changed

csharp/ql/test/library-tests/dataflow/global/Capture.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ void M()
4747
};
4848
};
4949
CaptureIn2NotCalled();
50-
/* void CaptureTest(string nonSink0, string sink39)
50+
void CaptureTest(string nonSink0, string sink39)
5151
{
5252
RunAction(() => // Check each lambda captures the correct arguments
5353
{
@@ -58,7 +58,7 @@ void M()
5858
});
5959
});
6060
}
61-
CaptureTest("not tainted", tainted);*/
61+
CaptureTest("not tainted", tainted);
6262
}
6363

6464
void Out()
@@ -187,8 +187,8 @@ string Id(string s)
187187

188188
static void Check<T>(T x) { }
189189

190-
/* static void RunAction(Action a)
190+
static void RunAction(Action a)
191191
{
192192
a.Invoke();
193-
}*/
193+
}
194194
}

csharp/ql/test/library-tests/dataflow/global/DataFlow.expected

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
| Capture.cs:12:19:12:24 | access to local variable sink27 |
22
| Capture.cs:21:23:21:28 | access to local variable sink28 |
33
| Capture.cs:30:19:30:24 | access to local variable sink29 |
4+
| Capture.cs:57:27:57:32 | access to parameter sink39 |
45
| Capture.cs:72:15:72:20 | access to local variable sink30 |
56
| Capture.cs:84:15:84:20 | access to local variable sink31 |
67
| Capture.cs:93:15:93:20 | access to local variable sink32 |

csharp/ql/test/library-tests/dataflow/global/DataFlowEdges.expected

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@
77
| Capture.cs:7:20:7:26 | tainted | Capture.cs:25:9:25:20 | [implicit argument] tainted |
88
| Capture.cs:7:20:7:26 | tainted | Capture.cs:33:9:33:40 | [implicit argument] tainted |
99
| Capture.cs:7:20:7:26 | tainted | Capture.cs:33:9:33:40 | [implicit argument] tainted |
10+
| Capture.cs:7:20:7:26 | tainted | Capture.cs:61:36:61:42 | access to parameter tainted |
11+
| Capture.cs:7:20:7:26 | tainted | Capture.cs:61:36:61:42 | access to parameter tainted |
1012
| Capture.cs:9:9:13:9 | SSA capture def(tainted) | Capture.cs:9:9:13:9 | SSA capture def(tainted) |
1113
| Capture.cs:9:9:13:9 | SSA capture def(tainted) | Capture.cs:11:17:11:32 | SSA def(sink27) |
1214
| Capture.cs:9:9:13:9 | SSA capture def(tainted) | Capture.cs:11:17:11:32 | SSA def(sink27) |
@@ -175,6 +177,58 @@
175177
| Capture.cs:46:23:46:30 | access to local variable nonSink0 | Capture.cs:46:23:46:30 | access to local variable nonSink0 |
176178
| Capture.cs:49:9:49:27 | access to local function CaptureIn2NotCalled | Capture.cs:49:9:49:27 | access to local function CaptureIn2NotCalled |
177179
| Capture.cs:49:9:49:29 | call to local function CaptureIn2NotCalled | Capture.cs:49:9:49:29 | call to local function CaptureIn2NotCalled |
180+
| Capture.cs:50:33:50:40 | nonSink0 | Capture.cs:50:33:50:40 | nonSink0 |
181+
| Capture.cs:50:33:50:40 | nonSink0 | Capture.cs:50:33:50:40 | nonSink0 |
182+
| Capture.cs:50:33:50:40 | nonSink0 | Capture.cs:52:13:59:14 | [implicit argument] nonSink0 |
183+
| Capture.cs:50:33:50:40 | nonSink0 | Capture.cs:52:13:59:14 | [implicit argument] nonSink0 |
184+
| Capture.cs:50:33:50:40 | nonSink0 | Capture.cs:52:13:59:14 | [implicit argument] nonSink0 |
185+
| Capture.cs:50:33:50:40 | nonSink0 | Capture.cs:52:13:59:14 | [implicit argument] nonSink0 |
186+
| Capture.cs:50:50:50:55 | sink39 | Capture.cs:50:50:50:55 | sink39 |
187+
| Capture.cs:50:50:50:55 | sink39 | Capture.cs:50:50:50:55 | sink39 |
188+
| Capture.cs:50:50:50:55 | sink39 | Capture.cs:52:13:59:14 | [implicit argument] sink39 |
189+
| Capture.cs:50:50:50:55 | sink39 | Capture.cs:52:13:59:14 | [implicit argument] sink39 |
190+
| Capture.cs:50:50:50:55 | sink39 | Capture.cs:52:13:59:14 | [implicit argument] sink39 |
191+
| Capture.cs:50:50:50:55 | sink39 | Capture.cs:52:13:59:14 | [implicit argument] sink39 |
192+
| Capture.cs:52:13:59:14 | [implicit argument] nonSink0 | Capture.cs:52:13:59:14 | [implicit argument] nonSink0 |
193+
| Capture.cs:52:13:59:14 | [implicit argument] nonSink0 | Capture.cs:52:23:59:13 | SSA capture def(nonSink0) |
194+
| Capture.cs:52:13:59:14 | [implicit argument] nonSink0 | Capture.cs:52:23:59:13 | SSA capture def(nonSink0) |
195+
| Capture.cs:52:13:59:14 | [implicit argument] nonSink0 | Capture.cs:52:23:59:13 | SSA capture def(nonSink0) |
196+
| Capture.cs:52:13:59:14 | [implicit argument] nonSink0 | Capture.cs:52:23:59:13 | SSA capture def(nonSink0) |
197+
| Capture.cs:52:13:59:14 | [implicit argument] sink39 | Capture.cs:52:13:59:14 | [implicit argument] sink39 |
198+
| Capture.cs:52:13:59:14 | [implicit argument] sink39 | Capture.cs:55:27:58:17 | SSA capture def(sink39) |
199+
| Capture.cs:52:13:59:14 | [implicit argument] sink39 | Capture.cs:55:27:58:17 | SSA capture def(sink39) |
200+
| Capture.cs:52:13:59:14 | [implicit argument] sink39 | Capture.cs:55:27:58:17 | SSA capture def(sink39) |
201+
| Capture.cs:52:13:59:14 | [implicit argument] sink39 | Capture.cs:55:27:58:17 | SSA capture def(sink39) |
202+
| Capture.cs:52:13:59:14 | call to method RunAction | Capture.cs:52:13:59:14 | call to method RunAction |
203+
| Capture.cs:52:23:59:13 | (...) => ... | Capture.cs:52:23:59:13 | (...) => ... |
204+
| Capture.cs:52:23:59:13 | (...) => ... | Capture.cs:190:34:190:34 | a |
205+
| Capture.cs:52:23:59:13 | (...) => ... | Capture.cs:190:34:190:34 | a |
206+
| Capture.cs:52:23:59:13 | SSA capture def(nonSink0) | Capture.cs:52:23:59:13 | SSA capture def(nonSink0) |
207+
| Capture.cs:52:23:59:13 | SSA capture def(nonSink0) | Capture.cs:54:23:54:30 | access to parameter nonSink0 |
208+
| Capture.cs:52:23:59:13 | SSA capture def(nonSink0) | Capture.cs:54:23:54:30 | access to parameter nonSink0 |
209+
| Capture.cs:52:23:59:13 | SSA capture def(nonSink0) | Capture.cs:54:23:54:30 | access to parameter nonSink0 |
210+
| Capture.cs:52:23:59:13 | SSA capture def(nonSink0) | Capture.cs:54:23:54:30 | access to parameter nonSink0 |
211+
| Capture.cs:54:17:54:31 | call to method Check | Capture.cs:54:17:54:31 | call to method Check |
212+
| Capture.cs:54:23:54:30 | access to parameter nonSink0 | Capture.cs:54:23:54:30 | access to parameter nonSink0 |
213+
| Capture.cs:55:17:58:18 | call to method RunAction | Capture.cs:55:17:58:18 | call to method RunAction |
214+
| Capture.cs:55:27:58:17 | (...) => ... | Capture.cs:55:27:58:17 | (...) => ... |
215+
| Capture.cs:55:27:58:17 | (...) => ... | Capture.cs:190:34:190:34 | a |
216+
| Capture.cs:55:27:58:17 | (...) => ... | Capture.cs:190:34:190:34 | a |
217+
| Capture.cs:55:27:58:17 | SSA capture def(sink39) | Capture.cs:55:27:58:17 | SSA capture def(sink39) |
218+
| Capture.cs:55:27:58:17 | SSA capture def(sink39) | Capture.cs:57:27:57:32 | access to parameter sink39 |
219+
| Capture.cs:55:27:58:17 | SSA capture def(sink39) | Capture.cs:57:27:57:32 | access to parameter sink39 |
220+
| Capture.cs:55:27:58:17 | SSA capture def(sink39) | Capture.cs:57:27:57:32 | access to parameter sink39 |
221+
| Capture.cs:55:27:58:17 | SSA capture def(sink39) | Capture.cs:57:27:57:32 | access to parameter sink39 |
222+
| Capture.cs:57:21:57:33 | call to method Check | Capture.cs:57:21:57:33 | call to method Check |
223+
| Capture.cs:57:27:57:32 | access to parameter sink39 | Capture.cs:57:27:57:32 | access to parameter sink39 |
224+
| Capture.cs:61:9:61:19 | access to local function CaptureTest | Capture.cs:61:9:61:19 | access to local function CaptureTest |
225+
| Capture.cs:61:9:61:43 | call to local function CaptureTest | Capture.cs:61:9:61:43 | call to local function CaptureTest |
226+
| Capture.cs:61:21:61:33 | "not tainted" | Capture.cs:50:33:50:40 | nonSink0 |
227+
| Capture.cs:61:21:61:33 | "not tainted" | Capture.cs:50:33:50:40 | nonSink0 |
228+
| Capture.cs:61:21:61:33 | "not tainted" | Capture.cs:61:21:61:33 | "not tainted" |
229+
| Capture.cs:61:36:61:42 | access to parameter tainted | Capture.cs:50:50:50:55 | sink39 |
230+
| Capture.cs:61:36:61:42 | access to parameter tainted | Capture.cs:50:50:50:55 | sink39 |
231+
| Capture.cs:61:36:61:42 | access to parameter tainted | Capture.cs:61:36:61:42 | access to parameter tainted |
178232
| Capture.cs:64:10:64:12 | this | Capture.cs:64:10:64:12 | this |
179233
| Capture.cs:66:16:66:26 | SSA def(sink30) | Capture.cs:66:16:66:26 | SSA def(sink30) |
180234
| Capture.cs:66:16:66:26 | String sink30 = ... | Capture.cs:66:16:66:26 | String sink30 = ... |
@@ -585,6 +639,16 @@
585639
| Capture.cs:184:23:184:24 | "" | Capture.cs:184:23:184:24 | "" |
586640
| Capture.cs:185:9:185:23 | call to method Check | Capture.cs:185:9:185:23 | call to method Check |
587641
| Capture.cs:185:15:185:22 | access to local variable nonSink0 | Capture.cs:185:15:185:22 | access to local variable nonSink0 |
642+
| Capture.cs:190:34:190:34 | a | Capture.cs:190:34:190:34 | a |
643+
| Capture.cs:190:34:190:34 | a | Capture.cs:190:34:190:34 | a |
644+
| Capture.cs:190:34:190:34 | a | Capture.cs:192:9:192:9 | access to parameter a |
645+
| Capture.cs:190:34:190:34 | a | Capture.cs:192:9:192:9 | access to parameter a |
646+
| Capture.cs:190:34:190:34 | a | Capture.cs:192:9:192:9 | access to parameter a |
647+
| Capture.cs:190:34:190:34 | a | Capture.cs:192:9:192:9 | access to parameter a |
648+
| Capture.cs:190:34:190:34 | a | Capture.cs:192:9:192:9 | access to parameter a |
649+
| Capture.cs:190:34:190:34 | a | Capture.cs:192:9:192:9 | access to parameter a |
650+
| Capture.cs:192:9:192:9 | access to parameter a | Capture.cs:192:9:192:9 | access to parameter a |
651+
| Capture.cs:192:9:192:18 | delegate call | Capture.cs:192:9:192:18 | delegate call |
588652
| GlobalDataFlow.cs:14:17:14:17 | this | GlobalDataFlow.cs:14:17:14:17 | this |
589653
| GlobalDataFlow.cs:14:17:14:17 | this | GlobalDataFlow.cs:64:9:64:18 | this access |
590654
| GlobalDataFlow.cs:14:17:14:17 | this | GlobalDataFlow.cs:64:9:64:18 | this access |

csharp/ql/test/library-tests/dataflow/global/DataFlowPath.expected

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,17 @@ edges
22
| Capture.cs:7:20:7:26 | tainted | Capture.cs:14:9:14:20 | [implicit argument] tainted |
33
| Capture.cs:7:20:7:26 | tainted | Capture.cs:25:9:25:20 | [implicit argument] tainted |
44
| Capture.cs:7:20:7:26 | tainted | Capture.cs:33:9:33:40 | [implicit argument] tainted |
5+
| Capture.cs:7:20:7:26 | tainted | Capture.cs:61:36:61:42 | access to parameter tainted |
56
| Capture.cs:9:9:13:9 | SSA capture def(tainted) | Capture.cs:12:19:12:24 | access to local variable sink27 |
67
| Capture.cs:14:9:14:20 | [implicit argument] tainted | Capture.cs:9:9:13:9 | SSA capture def(tainted) |
78
| Capture.cs:18:13:22:13 | SSA capture def(tainted) | Capture.cs:21:23:21:28 | access to local variable sink28 |
89
| Capture.cs:25:9:25:20 | [implicit argument] tainted | Capture.cs:18:13:22:13 | SSA capture def(tainted) |
910
| Capture.cs:27:43:32:9 | SSA capture def(tainted) | Capture.cs:30:19:30:24 | access to local variable sink29 |
1011
| Capture.cs:33:9:33:40 | [implicit argument] tainted | Capture.cs:27:43:32:9 | SSA capture def(tainted) |
12+
| Capture.cs:50:50:50:55 | sink39 | Capture.cs:52:13:59:14 | [implicit argument] sink39 |
13+
| Capture.cs:52:13:59:14 | [implicit argument] sink39 | Capture.cs:55:27:58:17 | SSA capture def(sink39) |
14+
| Capture.cs:55:27:58:17 | SSA capture def(sink39) | Capture.cs:57:27:57:32 | access to parameter sink39 |
15+
| Capture.cs:61:36:61:42 | access to parameter tainted | Capture.cs:50:50:50:55 | sink39 |
1116
| Capture.cs:69:13:69:35 | SSA def(sink30) | Capture.cs:71:9:71:21 | SSA call def(sink30) |
1217
| Capture.cs:69:22:69:35 | "taint source" | Capture.cs:69:13:69:35 | SSA def(sink30) |
1318
| Capture.cs:71:9:71:21 | SSA call def(sink30) | Capture.cs:72:15:72:20 | access to local variable sink30 |
@@ -227,6 +232,7 @@ edges
227232
| GlobalDataFlow.cs:181:15:181:19 | access to local variable sink9 | GlobalDataFlow.cs:179:35:179:48 | "taint source" | GlobalDataFlow.cs:181:15:181:19 | access to local variable sink9 | access to local variable sink9 |
228233
| Splitting.cs:11:19:11:19 | access to local variable x | Splitting.cs:3:28:3:34 | tainted | Splitting.cs:11:19:11:19 | access to local variable x | access to local variable x |
229234
| Splitting.cs:34:19:34:19 | access to local variable x | Splitting.cs:24:28:24:34 | tainted | Splitting.cs:34:19:34:19 | access to local variable x | access to local variable x |
235+
| Capture.cs:57:27:57:32 | access to parameter sink39 | Capture.cs:7:20:7:26 | tainted | Capture.cs:57:27:57:32 | access to parameter sink39 | access to parameter sink39 |
230236
| GlobalDataFlow.cs:237:15:237:24 | access to parameter sinkParam0 | GlobalDataFlow.cs:17:27:17:40 | "taint source" | GlobalDataFlow.cs:237:15:237:24 | access to parameter sinkParam0 | access to parameter sinkParam0 |
231237
| GlobalDataFlow.cs:242:15:242:24 | access to parameter sinkParam1 | GlobalDataFlow.cs:17:27:17:40 | "taint source" | GlobalDataFlow.cs:242:15:242:24 | access to parameter sinkParam1 | access to parameter sinkParam1 |
232238
| GlobalDataFlow.cs:44:50:44:59 | access to parameter sinkParam2 | GlobalDataFlow.cs:17:27:17:40 | "taint source" | GlobalDataFlow.cs:44:50:44:59 | access to parameter sinkParam2 | access to parameter sinkParam2 |

csharp/ql/test/library-tests/dataflow/global/TaintTracking.expected

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
| Capture.cs:12:19:12:24 | access to local variable sink27 |
22
| Capture.cs:21:23:21:28 | access to local variable sink28 |
33
| Capture.cs:30:19:30:24 | access to local variable sink29 |
4+
| Capture.cs:57:27:57:32 | access to parameter sink39 |
45
| Capture.cs:72:15:72:20 | access to local variable sink30 |
56
| Capture.cs:84:15:84:20 | access to local variable sink31 |
67
| Capture.cs:93:15:93:20 | access to local variable sink32 |

0 commit comments

Comments
 (0)