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
445 lines (351 loc) · 10.1 KB
/
ExternalFlow.cs
File metadata and controls
445 lines (351 loc) · 10.1 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
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
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) => null;
object GeneratedFlowArgs(object o1, object o2) => 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) { }
}
// Test extensions
public static class TestExtensions
{
extension(object o)
{
public object Method1() => throw null;
public static object StaticMethod1(object s) => throw null;
public object Property1 { get { throw null; } set { throw null; } }
}
extension<T>(T t) where T : class
{
public T GenericMethod1() => throw null;
public static T GenericStaticMethod1(T t0) => throw null;
public T GenericProperty1 { get { throw null; } set { throw null; } }
}
}
public class M
{
public void M1()
{
var obj = new object();
var o1 = obj.Method1();
Sink(o1);
var o2 = TestExtensions.Method1(obj);
Sink(o2);
}
public void M2()
{
var obj = new object();
var o1 = object.StaticMethod1(obj);
Sink(o1);
var o2 = TestExtensions.StaticMethod1(obj);
Sink(o2);
}
public void M3(object o)
{
var obj = new object();
o.Property1 = obj;
var o1 = o.Property1;
Sink(o1);
}
public void M4(object o)
{
var obj = new object();
TestExtensions.set_Property1(o, obj);
var o1 = TestExtensions.get_Property1(o);
Sink(o1);
}
public void M5()
{
var obj = new object();
var o1 = obj.GenericMethod1();
Sink(o1);
var o2 = TestExtensions.GenericMethod1(obj);
Sink(o2);
}
public void M6()
{
var obj = new object();
var o1 = object.GenericStaticMethod1(obj);
Sink(o1);
var o2 = TestExtensions.GenericStaticMethod1(obj);
Sink(o2);
}
public void M7(object o)
{
var obj = new object();
o.GenericProperty1 = obj;
var o1 = o.GenericProperty1;
Sink(o1);
}
public void M8(object o)
{
var obj = new object();
TestExtensions.set_GenericProperty1(o, obj);
var o1 = TestExtensions.get_GenericProperty1(o);
Sink(o1);
}
static void Sink(object o) { }
}
}