Skip to content

Commit 4018db1

Browse files
committed
C#: Add tests and update expected test output.
1 parent 37e4db5 commit 4018db1

12 files changed

Lines changed: 1054 additions & 595 deletions

File tree

csharp/ql/test/library-tests/dataflow/extensions/ExtensionFlow.expected

Lines changed: 506 additions & 438 deletions
Large diffs are not rendered by default.

csharp/ql/test/library-tests/dataflow/extensions/extensions.cs

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,14 @@ public void B2()
8686
}
8787
}
8888

89+
extension(C c)
90+
{
91+
public void operator *=(C c1)
92+
{
93+
c.Prop = c1.Prop;
94+
}
95+
}
96+
8997
extension<T>(T t) where T : class
9098
{
9199
public void GenericM1()
@@ -236,8 +244,26 @@ public void Test14()
236244
Sink(b3); // $ hasValueFlow=14
237245
}
238246

247+
public void Test15()
248+
{
249+
var c1 = new C();
250+
c1.Prop = Source<object>(15);
251+
var c2 = new C();
252+
c2 *= c1;
253+
Sink(c2.Prop); // $ hasValueFlow=15
254+
255+
var c3 = new C();
256+
MyExtensions.op_MultiplicationAssignment(c3, c1);
257+
Sink(c3.Prop); // $ hasValueFlow=15
258+
}
259+
239260
public static T Source<T>(object source) => throw null;
240261
public static void Sink(object o) { }
241262
}
242263

243264
public class B { }
265+
266+
public class C
267+
{
268+
public object Prop { get; set; }
269+
}

csharp/ql/test/library-tests/dataflow/operators/Operator.cs

Lines changed: 36 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,4 +84,39 @@ public void M6()
8484
var y = Source<C>(12);
8585
M6Aux(x, y);
8686
}
87-
}
87+
}
88+
89+
public class CompoundAssignmentOperators
90+
{
91+
static void Sink(object o) { }
92+
static T Source<T>(object source) => throw null;
93+
94+
public class C
95+
{
96+
public object Field { get; private set; }
97+
98+
public C()
99+
{
100+
Field = new object();
101+
}
102+
103+
public C(object o)
104+
{
105+
Field = o;
106+
}
107+
108+
public void operator +=(C x)
109+
{
110+
Field = x.Field;
111+
}
112+
}
113+
114+
public void M1()
115+
{
116+
var tainted = Source<object>(1);
117+
var x = new C();
118+
var y = new C(tainted);
119+
x += y;
120+
Sink(x.Field); // $ hasValueFlow=1
121+
}
122+
}

csharp/ql/test/library-tests/dataflow/operators/operatorFlow.expected

Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,40 @@ edges
9696
| Operator.cs:84:17:84:29 | call to method Source<C> : C | Operator.cs:84:13:84:13 | access to local variable y : C | provenance | |
9797
| Operator.cs:85:18:85:18 | access to local variable y : C | Operator.cs:75:33:75:33 | y : C | provenance | |
9898
| Operator.cs:85:18:85:18 | access to local variable y : C | Operator.cs:75:33:75:33 | y : C | provenance | |
99+
| Operator.cs:103:25:103:25 | o : Object | Operator.cs:105:21:105:21 | access to parameter o : Object | provenance | |
100+
| Operator.cs:103:25:103:25 | o : Object | Operator.cs:105:21:105:21 | access to parameter o : Object | provenance | |
101+
| Operator.cs:105:13:105:17 | [post] this access : C [property Field] : Object | Operator.cs:103:16:103:16 | this [Return] : C [property Field] : Object | provenance | |
102+
| Operator.cs:105:13:105:17 | [post] this access : C [property Field] : Object | Operator.cs:103:16:103:16 | this [Return] : C [property Field] : Object | provenance | |
103+
| Operator.cs:105:21:105:21 | access to parameter o : Object | Operator.cs:105:13:105:17 | [post] this access : C [property Field] : Object | provenance | |
104+
| Operator.cs:105:21:105:21 | access to parameter o : Object | Operator.cs:105:13:105:17 | [post] this access : C [property Field] : Object | provenance | |
105+
| Operator.cs:108:35:108:35 | x : C [property Field] : Object | Operator.cs:110:21:110:21 | access to parameter x : C [property Field] : Object | provenance | |
106+
| Operator.cs:108:35:108:35 | x : C [property Field] : Object | Operator.cs:110:21:110:21 | access to parameter x : C [property Field] : Object | provenance | |
107+
| Operator.cs:110:13:110:17 | [post] this access : C [property Field] : Object | Operator.cs:108:30:108:31 | this [Return] : C [property Field] : Object | provenance | |
108+
| Operator.cs:110:13:110:17 | [post] this access : C [property Field] : Object | Operator.cs:108:30:108:31 | this [Return] : C [property Field] : Object | provenance | |
109+
| Operator.cs:110:21:110:21 | access to parameter x : C [property Field] : Object | Operator.cs:110:21:110:27 | access to property Field : Object | provenance | |
110+
| Operator.cs:110:21:110:21 | access to parameter x : C [property Field] : Object | Operator.cs:110:21:110:27 | access to property Field : Object | provenance | |
111+
| Operator.cs:110:21:110:27 | access to property Field : Object | Operator.cs:110:13:110:17 | [post] this access : C [property Field] : Object | provenance | |
112+
| Operator.cs:110:21:110:27 | access to property Field : Object | Operator.cs:110:13:110:17 | [post] this access : C [property Field] : Object | provenance | |
113+
| Operator.cs:116:13:116:19 | access to local variable tainted : Object | Operator.cs:118:23:118:29 | access to local variable tainted : Object | provenance | |
114+
| Operator.cs:116:13:116:19 | access to local variable tainted : Object | Operator.cs:118:23:118:29 | access to local variable tainted : Object | provenance | |
115+
| Operator.cs:116:23:116:39 | call to method Source<Object> : Object | Operator.cs:116:13:116:19 | access to local variable tainted : Object | provenance | |
116+
| Operator.cs:116:23:116:39 | call to method Source<Object> : Object | Operator.cs:116:13:116:19 | access to local variable tainted : Object | provenance | |
117+
| Operator.cs:118:13:118:13 | access to local variable y : C [property Field] : Object | Operator.cs:119:14:119:14 | access to local variable y : C [property Field] : Object | provenance | |
118+
| Operator.cs:118:13:118:13 | access to local variable y : C [property Field] : Object | Operator.cs:119:14:119:14 | access to local variable y : C [property Field] : Object | provenance | |
119+
| Operator.cs:118:17:118:30 | object creation of type C : C [property Field] : Object | Operator.cs:118:13:118:13 | access to local variable y : C [property Field] : Object | provenance | |
120+
| Operator.cs:118:17:118:30 | object creation of type C : C [property Field] : Object | Operator.cs:118:13:118:13 | access to local variable y : C [property Field] : Object | provenance | |
121+
| Operator.cs:118:23:118:29 | access to local variable tainted : Object | Operator.cs:103:25:103:25 | o : Object | provenance | |
122+
| Operator.cs:118:23:118:29 | access to local variable tainted : Object | Operator.cs:103:25:103:25 | o : Object | provenance | |
123+
| Operator.cs:118:23:118:29 | access to local variable tainted : Object | Operator.cs:118:17:118:30 | object creation of type C : C [property Field] : Object | provenance | |
124+
| Operator.cs:118:23:118:29 | access to local variable tainted : Object | Operator.cs:118:17:118:30 | object creation of type C : C [property Field] : Object | provenance | |
125+
| Operator.cs:119:9:119:9 | [post] access to local variable x : C [property Field] : Object | Operator.cs:120:14:120:14 | access to local variable x : C [property Field] : Object | provenance | |
126+
| Operator.cs:119:9:119:9 | [post] access to local variable x : C [property Field] : Object | Operator.cs:120:14:120:14 | access to local variable x : C [property Field] : Object | provenance | |
127+
| Operator.cs:119:14:119:14 | access to local variable y : C [property Field] : Object | Operator.cs:108:35:108:35 | x : C [property Field] : Object | provenance | |
128+
| Operator.cs:119:14:119:14 | access to local variable y : C [property Field] : Object | Operator.cs:108:35:108:35 | x : C [property Field] : Object | provenance | |
129+
| Operator.cs:119:14:119:14 | access to local variable y : C [property Field] : Object | Operator.cs:119:9:119:9 | [post] access to local variable x : C [property Field] : Object | provenance | |
130+
| Operator.cs:119:14:119:14 | access to local variable y : C [property Field] : Object | Operator.cs:119:9:119:9 | [post] access to local variable x : C [property Field] : Object | provenance | |
131+
| Operator.cs:120:14:120:14 | access to local variable x : C [property Field] : Object | Operator.cs:120:14:120:20 | access to property Field | provenance | |
132+
| Operator.cs:120:14:120:14 | access to local variable x : C [property Field] : Object | Operator.cs:120:14:120:20 | access to property Field | provenance | |
99133
nodes
100134
| Operator.cs:9:39:9:39 | x : C | semmle.label | x : C |
101135
| Operator.cs:9:39:9:39 | x : C | semmle.label | x : C |
@@ -205,6 +239,42 @@ nodes
205239
| Operator.cs:84:17:84:29 | call to method Source<C> : C | semmle.label | call to method Source<C> : C |
206240
| Operator.cs:85:18:85:18 | access to local variable y : C | semmle.label | access to local variable y : C |
207241
| Operator.cs:85:18:85:18 | access to local variable y : C | semmle.label | access to local variable y : C |
242+
| Operator.cs:103:16:103:16 | this [Return] : C [property Field] : Object | semmle.label | this [Return] : C [property Field] : Object |
243+
| Operator.cs:103:16:103:16 | this [Return] : C [property Field] : Object | semmle.label | this [Return] : C [property Field] : Object |
244+
| Operator.cs:103:25:103:25 | o : Object | semmle.label | o : Object |
245+
| Operator.cs:103:25:103:25 | o : Object | semmle.label | o : Object |
246+
| Operator.cs:105:13:105:17 | [post] this access : C [property Field] : Object | semmle.label | [post] this access : C [property Field] : Object |
247+
| Operator.cs:105:13:105:17 | [post] this access : C [property Field] : Object | semmle.label | [post] this access : C [property Field] : Object |
248+
| Operator.cs:105:21:105:21 | access to parameter o : Object | semmle.label | access to parameter o : Object |
249+
| Operator.cs:105:21:105:21 | access to parameter o : Object | semmle.label | access to parameter o : Object |
250+
| Operator.cs:108:30:108:31 | this [Return] : C [property Field] : Object | semmle.label | this [Return] : C [property Field] : Object |
251+
| Operator.cs:108:30:108:31 | this [Return] : C [property Field] : Object | semmle.label | this [Return] : C [property Field] : Object |
252+
| Operator.cs:108:35:108:35 | x : C [property Field] : Object | semmle.label | x : C [property Field] : Object |
253+
| Operator.cs:108:35:108:35 | x : C [property Field] : Object | semmle.label | x : C [property Field] : Object |
254+
| Operator.cs:110:13:110:17 | [post] this access : C [property Field] : Object | semmle.label | [post] this access : C [property Field] : Object |
255+
| Operator.cs:110:13:110:17 | [post] this access : C [property Field] : Object | semmle.label | [post] this access : C [property Field] : Object |
256+
| Operator.cs:110:21:110:21 | access to parameter x : C [property Field] : Object | semmle.label | access to parameter x : C [property Field] : Object |
257+
| Operator.cs:110:21:110:21 | access to parameter x : C [property Field] : Object | semmle.label | access to parameter x : C [property Field] : Object |
258+
| Operator.cs:110:21:110:27 | access to property Field : Object | semmle.label | access to property Field : Object |
259+
| Operator.cs:110:21:110:27 | access to property Field : Object | semmle.label | access to property Field : Object |
260+
| Operator.cs:116:13:116:19 | access to local variable tainted : Object | semmle.label | access to local variable tainted : Object |
261+
| Operator.cs:116:13:116:19 | access to local variable tainted : Object | semmle.label | access to local variable tainted : Object |
262+
| Operator.cs:116:23:116:39 | call to method Source<Object> : Object | semmle.label | call to method Source<Object> : Object |
263+
| Operator.cs:116:23:116:39 | call to method Source<Object> : Object | semmle.label | call to method Source<Object> : Object |
264+
| Operator.cs:118:13:118:13 | access to local variable y : C [property Field] : Object | semmle.label | access to local variable y : C [property Field] : Object |
265+
| Operator.cs:118:13:118:13 | access to local variable y : C [property Field] : Object | semmle.label | access to local variable y : C [property Field] : Object |
266+
| Operator.cs:118:17:118:30 | object creation of type C : C [property Field] : Object | semmle.label | object creation of type C : C [property Field] : Object |
267+
| Operator.cs:118:17:118:30 | object creation of type C : C [property Field] : Object | semmle.label | object creation of type C : C [property Field] : Object |
268+
| Operator.cs:118:23:118:29 | access to local variable tainted : Object | semmle.label | access to local variable tainted : Object |
269+
| Operator.cs:118:23:118:29 | access to local variable tainted : Object | semmle.label | access to local variable tainted : Object |
270+
| Operator.cs:119:9:119:9 | [post] access to local variable x : C [property Field] : Object | semmle.label | [post] access to local variable x : C [property Field] : Object |
271+
| Operator.cs:119:9:119:9 | [post] access to local variable x : C [property Field] : Object | semmle.label | [post] access to local variable x : C [property Field] : Object |
272+
| Operator.cs:119:14:119:14 | access to local variable y : C [property Field] : Object | semmle.label | access to local variable y : C [property Field] : Object |
273+
| Operator.cs:119:14:119:14 | access to local variable y : C [property Field] : Object | semmle.label | access to local variable y : C [property Field] : Object |
274+
| Operator.cs:120:14:120:14 | access to local variable x : C [property Field] : Object | semmle.label | access to local variable x : C [property Field] : Object |
275+
| Operator.cs:120:14:120:14 | access to local variable x : C [property Field] : Object | semmle.label | access to local variable x : C [property Field] : Object |
276+
| Operator.cs:120:14:120:20 | access to property Field | semmle.label | access to property Field |
277+
| Operator.cs:120:14:120:20 | access to property Field | semmle.label | access to property Field |
208278
subpaths
209279
| Operator.cs:29:17:29:17 | access to local variable x : C | Operator.cs:16:38:16:38 | x : C | Operator.cs:16:49:16:49 | access to parameter x : C | Operator.cs:29:17:29:21 | call to operator + : C |
210280
| Operator.cs:29:17:29:17 | access to local variable x : C | Operator.cs:16:38:16:38 | x : C | Operator.cs:16:49:16:49 | access to parameter x : C | Operator.cs:29:17:29:21 | call to operator + : C |
@@ -218,6 +288,10 @@ subpaths
218288
| Operator.cs:64:21:64:21 | access to parameter y : C | Operator.cs:21:43:21:43 | y : C | Operator.cs:21:49:21:49 | access to parameter y : C | Operator.cs:64:17:64:21 | call to operator / : C |
219289
| Operator.cs:77:29:77:29 | access to parameter y : C | Operator.cs:22:51:22:51 | y : C | Operator.cs:22:57:22:57 | access to parameter y : C | Operator.cs:77:25:77:29 | call to operator checked / : C |
220290
| Operator.cs:77:29:77:29 | access to parameter y : C | Operator.cs:22:51:22:51 | y : C | Operator.cs:22:57:22:57 | access to parameter y : C | Operator.cs:77:25:77:29 | call to operator checked / : C |
291+
| Operator.cs:118:23:118:29 | access to local variable tainted : Object | Operator.cs:103:25:103:25 | o : Object | Operator.cs:103:16:103:16 | this [Return] : C [property Field] : Object | Operator.cs:118:17:118:30 | object creation of type C : C [property Field] : Object |
292+
| Operator.cs:118:23:118:29 | access to local variable tainted : Object | Operator.cs:103:25:103:25 | o : Object | Operator.cs:103:16:103:16 | this [Return] : C [property Field] : Object | Operator.cs:118:17:118:30 | object creation of type C : C [property Field] : Object |
293+
| Operator.cs:119:14:119:14 | access to local variable y : C [property Field] : Object | Operator.cs:108:35:108:35 | x : C [property Field] : Object | Operator.cs:108:30:108:31 | this [Return] : C [property Field] : Object | Operator.cs:119:9:119:9 | [post] access to local variable x : C [property Field] : Object |
294+
| Operator.cs:119:14:119:14 | access to local variable y : C [property Field] : Object | Operator.cs:108:35:108:35 | x : C [property Field] : Object | Operator.cs:108:30:108:31 | this [Return] : C [property Field] : Object | Operator.cs:119:9:119:9 | [post] access to local variable x : C [property Field] : Object |
221295
testFailures
222296
#select
223297
| Operator.cs:30:14:30:14 | access to local variable z | Operator.cs:27:17:27:28 | call to method Source<C> : C | Operator.cs:30:14:30:14 | access to local variable z | $@ | Operator.cs:27:17:27:28 | call to method Source<C> : C | call to method Source<C> : C |
@@ -232,3 +306,5 @@ testFailures
232306
| Operator.cs:65:14:65:14 | (...) ... | Operator.cs:71:17:71:29 | call to method Source<C> : C | Operator.cs:65:14:65:14 | (...) ... | $@ | Operator.cs:71:17:71:29 | call to method Source<C> : C | call to method Source<C> : C |
233307
| Operator.cs:78:14:78:14 | (...) ... | Operator.cs:84:17:84:29 | call to method Source<C> : C | Operator.cs:78:14:78:14 | (...) ... | $@ | Operator.cs:84:17:84:29 | call to method Source<C> : C | call to method Source<C> : C |
234308
| Operator.cs:78:14:78:14 | (...) ... | Operator.cs:84:17:84:29 | call to method Source<C> : C | Operator.cs:78:14:78:14 | (...) ... | $@ | Operator.cs:84:17:84:29 | call to method Source<C> : C | call to method Source<C> : C |
309+
| Operator.cs:120:14:120:20 | access to property Field | Operator.cs:116:23:116:39 | call to method Source<Object> : Object | Operator.cs:120:14:120:20 | access to property Field | $@ | Operator.cs:116:23:116:39 | call to method Source<Object> : Object | call to method Source<Object> : Object |
310+
| Operator.cs:120:14:120:20 | access to property Field | Operator.cs:116:23:116:39 | call to method Source<Object> : Object | Operator.cs:120:14:120:20 | access to property Field | $@ | Operator.cs:116:23:116:39 | call to method Source<Object> : Object | call to method Source<Object> : Object |
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
| operators.cs:16:42:16:43 | ++ | operators.cs:7:18:7:26 | IntVector |
1+
| operators.cs:15:42:15:43 | ++ | operators.cs:7:18:7:26 | IntVector |
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
| operators.cs:16:42:16:43 | ++ | operators.cs:7:18:7:26 | IntVector |
1+
| operators.cs:15:42:15:43 | ++ | operators.cs:7:18:7:26 | IntVector |
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
| operators.cs:51:32:51:39 | implicit conversion |
1+
| operators.cs:96:32:96:39 | implicit conversion |
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
| operators.cs:56:32:56:39 | explicit conversion |
1+
| operators.cs:101:32:101:39 | explicit conversion |
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
| operators.cs:23:30:23:31 | += | operators.cs:61:13:61:22 | ... += ... |
2+
| operators.cs:31:38:31:39 | checked += | operators.cs:77:17:77:26 | ... += ... |
3+
| operators.cs:33:38:33:39 | checked -= | operators.cs:78:17:78:26 | ... -= ... |
4+
| operators.cs:34:30:34:31 | -= | operators.cs:64:13:64:22 | ... -= ... |
5+
| operators.cs:36:38:36:39 | checked *= | operators.cs:79:17:79:26 | ... *= ... |
6+
| operators.cs:37:30:37:31 | *= | operators.cs:65:13:65:22 | ... *= ... |
7+
| operators.cs:39:38:39:39 | checked /= | operators.cs:80:17:80:26 | ... /= ... |
8+
| operators.cs:40:30:40:31 | /= | operators.cs:66:13:66:22 | ... /= ... |
9+
| operators.cs:42:30:42:31 | %= | operators.cs:67:13:67:22 | ... %= ... |
10+
| operators.cs:43:30:43:31 | &= | operators.cs:68:13:68:22 | ... &= ... |
11+
| operators.cs:44:30:44:31 | \|= | operators.cs:69:13:69:22 | ... \|= ... |
12+
| operators.cs:45:30:45:31 | ^= | operators.cs:70:13:70:22 | ... ^= ... |
13+
| operators.cs:46:30:46:32 | <<= | operators.cs:71:13:71:23 | ... <<= ... |
14+
| operators.cs:47:30:47:32 | >>= | operators.cs:72:13:72:23 | ... >>= ... |
15+
| operators.cs:48:30:48:33 | >>>= | operators.cs:73:13:73:24 | ... >>>= ... |
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
/**
2+
* @name Test for operators
3+
*/
4+
5+
import csharp
6+
7+
from CompoundAssignmentOperator cao, CompoundAssignmentOperatorCall call
8+
where call.getTarget() = cao
9+
select cao, call

0 commit comments

Comments
 (0)