forked from github/codeql
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathExternalFlow.cs
More file actions
351 lines (271 loc) · 7.74 KB
/
ExternalFlow.cs
File metadata and controls
351 lines (271 loc) · 7.74 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
using System;
namespace My.Qltest
{
public class D
{
void M1()
{
object arg1 = new object();
Sink(StepArgRes(arg1));
}
void M2()
{
object argIn1 = new object();
object argOut1 = new object();
StepArgArg(argIn1, argOut1);
Sink(argOut1);
}
void M3()
{
object arg2 = new object();
StepArgQual(arg2);
Sink(this);
}
void M4()
{
this.Field = new object();
Sink(this.StepFieldGetter());
}
void M5()
{
Sink(((D)this.StepFieldSetter(new object()).Field2).Field);
Sink(this.Field);
}
void M6()
{
this.Property = new object();
Sink(this.StepPropertyGetter());
}
void M7()
{
this.StepPropertySetter(new object());
Sink(this.Property);
}
void M8()
{
this.StepElementSetter(new object());
Sink(this.StepElementGetter());
}
void M9()
{
Apply<object, object>(o => { Sink(o); return o; }, new object());
}
void M10()
{
var o = Apply<int, object>(_ => new object(), 0);
Sink(o);
}
void M11()
{
var objs = new[] { new object() };
Map(objs, o => { Sink(o); return o; });
}
void M12()
{
var objs = Map(new[] { 0 }, _ => new object());
Sink(objs[0]);
}
void M13()
{
var objs = new[] { new object() };
var objs2 = Map(objs, o => o);
Sink(objs2[0]);
}
void M14()
{
var s = new string("");
Parse(s, out var i);
Sink(i);
}
void M15()
{
var d1 = new D();
d1.Field = new object();
var d2 = new D();
Apply2(d =>
{
Sink(d);
}, d1, d2);
Sink(d1.Field);
Sink(d2.Field2);
}
void M16()
{
var f = new F();
f.MyProp = new object();
Sink(f.MyProp);
}
void M17()
{
var a = new object[] { new object() };
var b = Reverse(a);
Sink(b); // Flow
Sink(b[0]); // Flow
}
object StepArgRes(object x) { return null; }
void StepArgArg(object @in, object @out) { }
void StepArgQual(object x) { }
object StepQualRes() { return null; }
void StepQualArg(object @out) { }
object Field;
object Field2;
object StepFieldGetter() => throw null;
D StepFieldSetter(object value) => throw null;
object Property { get; set; }
object StepPropertyGetter() => throw null;
void StepPropertySetter(object value) => throw null;
object StepElementGetter() => throw null;
void StepElementSetter(object value) => throw null;
static T Apply<S, T>(Func<S, T> f, S s) => throw null;
static T[] Map<S, T>(S[] elements, Func<S, T> f) => throw null;
static void Apply2(Action<object> f, D d1, D d2) => throw null;
static void Parse(string s, out int i) => throw null;
static object[] Reverse(object[] elements) => throw null;
static void Sink(object o) { }
}
public class E
{
object MyField;
public virtual object MyProp
{
get { throw null; }
set { throw null; }
}
}
public class F : E
{
public override object MyProp
{
get { throw null; }
set { throw null; }
}
}
public class G
{
void M1()
{
var o = new object();
Sink(GeneratedFlow(o)); // no flow because the modelled method exists in source code
}
void M2()
{
var o1 = new object();
Sink(GeneratedFlowArgs(o1, null)); // no flow because the modelled method exists in source code
var o2 = new object();
Sink(GeneratedFlowArgs(null, o2)); // no flow because the modelled method exists in source code
}
void M3()
{
var o1 = new object();
Sink(Library.MixedFlowArgs(o1, null));
var o2 = new object();
Sink(Library.MixedFlowArgs(null, o2));
}
void M4()
{
var o1 = new object();
Sink(Library.GeneratedFlowWithGeneratedNeutral(o1));
var o2 = new object();
Sink(Library.GeneratedFlowWithManualNeutral(o2)); // no flow because the modelled method has a manual neutral summary model
}
object GeneratedFlow(object o) => throw null;
object GeneratedFlowArgs(object o1, object o2) => throw null;
static void Sink(object o) { }
}
public interface HI { }
public class HC : HI { }
public static class HE
{
public static object ExtensionMethod(this HI h) => throw null;
}
public class H
{
void M1()
{
var h = new HC();
var o = h.ExtensionMethod();
Sink(o);
}
static void Sink(object o) { }
}
[System.Runtime.CompilerServices.InlineArray(10)]
public struct MyInlineArray
{
private object myInlineArrayElements;
}
public class I
{
void M1(MyInlineArray a)
{
a[0] = new object();
var b = GetFirst(a);
Sink(b);
}
object GetFirst(MyInlineArray arr) => throw null;
static void Sink(object o) { }
}
public class J
{
public virtual object Prop1 { get; }
public virtual void SetProp1(object o) => throw null;
public virtual object Prop2 { get; }
public virtual void SetProp2(object o) => throw null;
void M1()
{
var j = new object();
SetProp1(j);
// flow as there is a manual summary.
Sink(this.Prop1);
}
void M2()
{
var j = new object();
SetProp2(j);
// no flow as there is only a generated summary and source code is available.
Sink(this.Prop2);
}
static void Sink(object o) { }
}
// Test synthetic fields
public class K
{
public object MyField;
public void SetMySyntheticField(object o) => throw null;
public object GetMySyntheticField() => throw null;
public void SetMyNestedSyntheticField(object o) => throw null;
public object GetMyNestedSyntheticField() => throw null;
public void SetMyFieldOnSyntheticField(object o) => throw null;
public object GetMyFieldOnSyntheticField() => throw null;
public void M1()
{
var o = new object();
SetMySyntheticField(o);
Sink(GetMySyntheticField());
}
public void M2()
{
var o = new object();
SetMyNestedSyntheticField(o);
Sink(GetMyNestedSyntheticField());
}
public void M3()
{
var o = new object();
SetMyFieldOnSyntheticField(o);
Sink(GetMyFieldOnSyntheticField());
}
static void Sink(object o) { }
}
// Test content data flow provenance.
public class L
{
public void M1()
{
var l = new Library();
var o = new object();
l.SetValue(o);
Sink(l.GetValue());
}
static void Sink(object o) { }
}
}