Skip to content

Commit f5d4c49

Browse files
committed
C#: Add some more constructor dataflow tests.
1 parent 86212b2 commit f5d4c49

File tree

2 files changed

+87
-0
lines changed

2 files changed

+87
-0
lines changed

csharp/ql/test/library-tests/dataflow/constructors/ConstructorFlow.expected

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,8 @@
11
testFailures
2+
| Constructors.cs:70:25:70:43 | // ... | Missing result:hasValueFlow=2 |
3+
| Constructors.cs:71:25:71:43 | // ... | Missing result:hasValueFlow=3 |
4+
| Constructors.cs:72:25:72:43 | // ... | Missing result:hasValueFlow=2 |
5+
| Constructors.cs:83:25:83:43 | // ... | Missing result:hasValueFlow=4 |
26
edges
37
| Constructors.cs:5:24:5:25 | [post] this access : C_no_ctor [field s1] : Object | Constructors.cs:9:27:9:41 | object creation of type C_no_ctor : C_no_ctor [field s1] : Object |
48
| Constructors.cs:5:24:5:25 | [post] this access : C_no_ctor [field s1] : Object | Constructors.cs:9:27:9:41 | object creation of type C_no_ctor : C_no_ctor [field s1] : Object |
@@ -24,6 +28,20 @@ edges
2428
| Constructors.cs:31:21:31:22 | this : C_with_ctor [field s1] : Object | Constructors.cs:33:18:33:19 | this access : C_with_ctor [field s1] : Object |
2529
| Constructors.cs:33:18:33:19 | this access : C_with_ctor [field s1] : Object | Constructors.cs:33:18:33:19 | access to field s1 |
2630
| Constructors.cs:33:18:33:19 | this access : C_with_ctor [field s1] : Object | Constructors.cs:33:18:33:19 | access to field s1 |
31+
| Constructors.cs:41:26:41:26 | o : Object | Constructors.cs:41:38:41:38 | access to parameter o : Object |
32+
| Constructors.cs:41:26:41:26 | o : Object | Constructors.cs:41:38:41:38 | access to parameter o : Object |
33+
| Constructors.cs:41:38:41:38 | access to parameter o : Object | Constructors.cs:41:32:41:34 | [post] this access : C1 [field Obj] : Object |
34+
| Constructors.cs:41:38:41:38 | access to parameter o : Object | Constructors.cs:41:32:41:34 | [post] this access : C1 [field Obj] : Object |
35+
| Constructors.cs:60:17:60:33 | call to method Source<Object> : Object | Constructors.cs:61:25:61:25 | access to local variable o : Object |
36+
| Constructors.cs:60:17:60:33 | call to method Source<Object> : Object | Constructors.cs:61:25:61:25 | access to local variable o : Object |
37+
| Constructors.cs:61:18:61:26 | object creation of type C1 : C1 [field Obj] : Object | Constructors.cs:62:14:62:15 | access to local variable c1 : C1 [field Obj] : Object |
38+
| Constructors.cs:61:18:61:26 | object creation of type C1 : C1 [field Obj] : Object | Constructors.cs:62:14:62:15 | access to local variable c1 : C1 [field Obj] : Object |
39+
| Constructors.cs:61:25:61:25 | access to local variable o : Object | Constructors.cs:41:26:41:26 | o : Object |
40+
| Constructors.cs:61:25:61:25 | access to local variable o : Object | Constructors.cs:41:26:41:26 | o : Object |
41+
| Constructors.cs:61:25:61:25 | access to local variable o : Object | Constructors.cs:61:18:61:26 | object creation of type C1 : C1 [field Obj] : Object |
42+
| Constructors.cs:61:25:61:25 | access to local variable o : Object | Constructors.cs:61:18:61:26 | object creation of type C1 : C1 [field Obj] : Object |
43+
| Constructors.cs:62:14:62:15 | access to local variable c1 : C1 [field Obj] : Object | Constructors.cs:62:14:62:19 | access to field Obj |
44+
| Constructors.cs:62:14:62:15 | access to local variable c1 : C1 [field Obj] : Object | Constructors.cs:62:14:62:19 | access to field Obj |
2745
nodes
2846
| Constructors.cs:5:24:5:25 | [post] this access : C_no_ctor [field s1] : Object | semmle.label | [post] this access : C_no_ctor [field s1] : Object |
2947
| Constructors.cs:5:24:5:25 | [post] this access : C_no_ctor [field s1] : Object | semmle.label | [post] this access : C_no_ctor [field s1] : Object |
@@ -53,9 +71,29 @@ nodes
5371
| Constructors.cs:33:18:33:19 | access to field s1 | semmle.label | access to field s1 |
5472
| Constructors.cs:33:18:33:19 | this access : C_with_ctor [field s1] : Object | semmle.label | this access : C_with_ctor [field s1] : Object |
5573
| Constructors.cs:33:18:33:19 | this access : C_with_ctor [field s1] : Object | semmle.label | this access : C_with_ctor [field s1] : Object |
74+
| Constructors.cs:41:26:41:26 | o : Object | semmle.label | o : Object |
75+
| Constructors.cs:41:26:41:26 | o : Object | semmle.label | o : Object |
76+
| Constructors.cs:41:32:41:34 | [post] this access : C1 [field Obj] : Object | semmle.label | [post] this access : C1 [field Obj] : Object |
77+
| Constructors.cs:41:32:41:34 | [post] this access : C1 [field Obj] : Object | semmle.label | [post] this access : C1 [field Obj] : Object |
78+
| Constructors.cs:41:38:41:38 | access to parameter o : Object | semmle.label | access to parameter o : Object |
79+
| Constructors.cs:41:38:41:38 | access to parameter o : Object | semmle.label | access to parameter o : Object |
80+
| Constructors.cs:60:17:60:33 | call to method Source<Object> : Object | semmle.label | call to method Source<Object> : Object |
81+
| Constructors.cs:60:17:60:33 | call to method Source<Object> : Object | semmle.label | call to method Source<Object> : Object |
82+
| Constructors.cs:61:18:61:26 | object creation of type C1 : C1 [field Obj] : Object | semmle.label | object creation of type C1 : C1 [field Obj] : Object |
83+
| Constructors.cs:61:18:61:26 | object creation of type C1 : C1 [field Obj] : Object | semmle.label | object creation of type C1 : C1 [field Obj] : Object |
84+
| Constructors.cs:61:25:61:25 | access to local variable o : Object | semmle.label | access to local variable o : Object |
85+
| Constructors.cs:61:25:61:25 | access to local variable o : Object | semmle.label | access to local variable o : Object |
86+
| Constructors.cs:62:14:62:15 | access to local variable c1 : C1 [field Obj] : Object | semmle.label | access to local variable c1 : C1 [field Obj] : Object |
87+
| Constructors.cs:62:14:62:15 | access to local variable c1 : C1 [field Obj] : Object | semmle.label | access to local variable c1 : C1 [field Obj] : Object |
88+
| Constructors.cs:62:14:62:19 | access to field Obj | semmle.label | access to field Obj |
89+
| Constructors.cs:62:14:62:19 | access to field Obj | semmle.label | access to field Obj |
5690
subpaths
91+
| Constructors.cs:61:25:61:25 | access to local variable o : Object | Constructors.cs:41:26:41:26 | o : Object | Constructors.cs:41:32:41:34 | [post] this access : C1 [field Obj] : Object | Constructors.cs:61:18:61:26 | object creation of type C1 : C1 [field Obj] : Object |
92+
| Constructors.cs:61:25:61:25 | access to local variable o : Object | Constructors.cs:41:26:41:26 | o : Object | Constructors.cs:41:32:41:34 | [post] this access : C1 [field Obj] : Object | Constructors.cs:61:18:61:26 | object creation of type C1 : C1 [field Obj] : Object |
5793
#select
5894
| Constructors.cs:15:18:15:19 | access to field s1 | Constructors.cs:5:29:5:45 | call to method Source<Object> : Object | Constructors.cs:15:18:15:19 | access to field s1 | $@ | Constructors.cs:5:29:5:45 | call to method Source<Object> : Object | call to method Source<Object> : Object |
5995
| Constructors.cs:15:18:15:19 | access to field s1 | Constructors.cs:5:29:5:45 | call to method Source<Object> : Object | Constructors.cs:15:18:15:19 | access to field s1 | $@ | Constructors.cs:5:29:5:45 | call to method Source<Object> : Object | call to method Source<Object> : Object |
6096
| Constructors.cs:33:18:33:19 | access to field s1 | Constructors.cs:21:29:21:45 | call to method Source<Object> : Object | Constructors.cs:33:18:33:19 | access to field s1 | $@ | Constructors.cs:21:29:21:45 | call to method Source<Object> : Object | call to method Source<Object> : Object |
6197
| Constructors.cs:33:18:33:19 | access to field s1 | Constructors.cs:21:29:21:45 | call to method Source<Object> : Object | Constructors.cs:33:18:33:19 | access to field s1 | $@ | Constructors.cs:21:29:21:45 | call to method Source<Object> : Object | call to method Source<Object> : Object |
98+
| Constructors.cs:62:14:62:19 | access to field Obj | Constructors.cs:60:17:60:33 | call to method Source<Object> : Object | Constructors.cs:62:14:62:19 | access to field Obj | $@ | Constructors.cs:60:17:60:33 | call to method Source<Object> : Object | call to method Source<Object> : Object |
99+
| Constructors.cs:62:14:62:19 | access to field Obj | Constructors.cs:60:17:60:33 | call to method Source<Object> : Object | Constructors.cs:62:14:62:19 | access to field Obj | $@ | Constructors.cs:60:17:60:33 | call to method Source<Object> : Object | call to method Source<Object> : Object |

csharp/ql/test/library-tests/dataflow/constructors/Constructors.cs

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,55 @@ public void M2()
3434
}
3535
}
3636

37+
public class C1
38+
{
39+
public object Obj;
40+
41+
public C1(object o) => Obj = o;
42+
}
43+
44+
public class C2(object o21param, object o22param)
45+
{
46+
public object Obj21 = o21param;
47+
48+
public object Obj22 => o22param;
49+
50+
public object Obj23 => Obj21;
51+
52+
public void SetObj(object o)
53+
{
54+
o22param = o;
55+
}
56+
}
57+
58+
public void M1()
59+
{
60+
var o = Source<object>(1);
61+
var c1 = new C1(o);
62+
Sink(c1.Obj); // $ hasValueFlow=1
63+
}
64+
65+
public void M2()
66+
{
67+
var o21 = Source<object>(2);
68+
var o22 = Source<object>(3);
69+
var c2 = new C2(o21, o22);
70+
Sink(c2.Obj21); // $ hasValueFlow=2
71+
Sink(c2.Obj22); // $ hasValueFlow=3
72+
Sink(c2.Obj23); // $ hasValueFlow=2
73+
}
74+
75+
public void M3()
76+
{
77+
var c2 = new C2(new object(), new object());
78+
Sink(c2.Obj21); // No flow
79+
Sink(c2.Obj22); // No flow
80+
Sink(c2.Obj23); // No flow
81+
var taint = Source<object>(4);
82+
c2.SetObj(taint);
83+
Sink(c2.Obj22); // $ hasValueFlow=4
84+
}
85+
3786
public static void Sink(object o) { }
3887

3988
public static T Source<T>(object source) => throw null;

0 commit comments

Comments
 (0)