Skip to content

Commit 213e391

Browse files
committed
C#: Add some more external flow testcases (one with a spurious result).
1 parent b08a0a3 commit 213e391

File tree

4 files changed

+58
-0
lines changed

4 files changed

+58
-0
lines changed

csharp/ql/test/library-tests/dataflow/external-models/ExternalFlow.cs

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -262,4 +262,33 @@ void M1(MyInlineArray a)
262262

263263
static void Sink(object o) { }
264264
}
265+
266+
public class J
267+
{
268+
public virtual object Prop1 { get; }
269+
270+
public virtual void SetProp1(object o) => throw null;
271+
272+
public virtual object Prop2 { get; }
273+
274+
public virtual void SetProp2(object o) => throw null;
275+
276+
void M1()
277+
{
278+
var j = new object();
279+
SetProp1(j);
280+
// flow as there is a manual summary.
281+
Sink(this.Prop1);
282+
}
283+
284+
void M2()
285+
{
286+
var j = new object();
287+
SetProp2(j);
288+
// no flow as there is only a generated summary and source code is available.
289+
Sink(this.Prop2);
290+
}
291+
292+
static void Sink(object o) { }
293+
}
265294
}

csharp/ql/test/library-tests/dataflow/external-models/ExternalFlow.expected

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,16 @@ edges
9191
| ExternalFlow.cs:257:17:257:17 | access to local variable b : Object | ExternalFlow.cs:258:18:258:18 | access to local variable b | provenance | |
9292
| ExternalFlow.cs:257:21:257:31 | call to method GetFirst : Object | ExternalFlow.cs:257:17:257:17 | access to local variable b : Object | provenance | |
9393
| ExternalFlow.cs:257:30:257:30 | access to parameter a : MyInlineArray [element] : Object | ExternalFlow.cs:257:21:257:31 | call to method GetFirst : Object | provenance | MaD:28 |
94+
| ExternalFlow.cs:278:17:278:17 | access to local variable j : Object | ExternalFlow.cs:279:22:279:22 | access to local variable j : Object | provenance | |
95+
| ExternalFlow.cs:278:21:278:32 | object creation of type Object : Object | ExternalFlow.cs:278:17:278:17 | access to local variable j : Object | provenance | |
96+
| ExternalFlow.cs:279:13:279:23 | [post] this access : J | ExternalFlow.cs:281:18:281:21 | this access : J | provenance | |
97+
| ExternalFlow.cs:279:22:279:22 | access to local variable j : Object | ExternalFlow.cs:279:13:279:23 | [post] this access : J | provenance | MaD:30 |
98+
| ExternalFlow.cs:281:18:281:21 | this access : J | ExternalFlow.cs:281:18:281:27 | access to property Prop1 | provenance | MaD:29 |
99+
| ExternalFlow.cs:286:17:286:17 | access to local variable j : Object | ExternalFlow.cs:287:22:287:22 | access to local variable j : Object | provenance | |
100+
| ExternalFlow.cs:286:21:286:32 | object creation of type Object : Object | ExternalFlow.cs:286:17:286:17 | access to local variable j : Object | provenance | |
101+
| ExternalFlow.cs:287:13:287:23 | [post] this access : J | ExternalFlow.cs:289:18:289:21 | this access : J | provenance | |
102+
| ExternalFlow.cs:287:22:287:22 | access to local variable j : Object | ExternalFlow.cs:287:13:287:23 | [post] this access : J | provenance | MaD:32 |
103+
| ExternalFlow.cs:289:18:289:21 | this access : J | ExternalFlow.cs:289:18:289:27 | access to property Prop2 | provenance | MaD:31 |
94104
nodes
95105
| ExternalFlow.cs:9:20:9:23 | access to local variable arg1 : Object | semmle.label | access to local variable arg1 : Object |
96106
| ExternalFlow.cs:9:27:9:38 | object creation of type Object : Object | semmle.label | object creation of type Object : Object |
@@ -204,6 +214,18 @@ nodes
204214
| ExternalFlow.cs:257:21:257:31 | call to method GetFirst : Object | semmle.label | call to method GetFirst : Object |
205215
| ExternalFlow.cs:257:30:257:30 | access to parameter a : MyInlineArray [element] : Object | semmle.label | access to parameter a : MyInlineArray [element] : Object |
206216
| ExternalFlow.cs:258:18:258:18 | access to local variable b | semmle.label | access to local variable b |
217+
| ExternalFlow.cs:278:17:278:17 | access to local variable j : Object | semmle.label | access to local variable j : Object |
218+
| ExternalFlow.cs:278:21:278:32 | object creation of type Object : Object | semmle.label | object creation of type Object : Object |
219+
| ExternalFlow.cs:279:13:279:23 | [post] this access : J | semmle.label | [post] this access : J |
220+
| ExternalFlow.cs:279:22:279:22 | access to local variable j : Object | semmle.label | access to local variable j : Object |
221+
| ExternalFlow.cs:281:18:281:21 | this access : J | semmle.label | this access : J |
222+
| ExternalFlow.cs:281:18:281:27 | access to property Prop1 | semmle.label | access to property Prop1 |
223+
| ExternalFlow.cs:286:17:286:17 | access to local variable j : Object | semmle.label | access to local variable j : Object |
224+
| ExternalFlow.cs:286:21:286:32 | object creation of type Object : Object | semmle.label | object creation of type Object : Object |
225+
| ExternalFlow.cs:287:13:287:23 | [post] this access : J | semmle.label | [post] this access : J |
226+
| ExternalFlow.cs:287:22:287:22 | access to local variable j : Object | semmle.label | access to local variable j : Object |
227+
| ExternalFlow.cs:289:18:289:21 | this access : J | semmle.label | this access : J |
228+
| ExternalFlow.cs:289:18:289:27 | access to property Prop2 | semmle.label | access to property Prop2 |
207229
subpaths
208230
| ExternalFlow.cs:84:29:84:32 | access to local variable objs : null [element] : Object | ExternalFlow.cs:84:35:84:35 | o : Object | ExternalFlow.cs:84:40:84:40 | access to parameter o : Object | ExternalFlow.cs:84:25:84:41 | call to method Map<Object,Object> : T[] [element] : Object |
209231
#select
@@ -231,3 +253,5 @@ subpaths
231253
| ExternalFlow.cs:212:18:212:62 | call to method GeneratedFlowWithGeneratedNeutral | ExternalFlow.cs:211:22:211:33 | object creation of type Object : Object | ExternalFlow.cs:212:18:212:62 | call to method GeneratedFlowWithGeneratedNeutral | $@ | ExternalFlow.cs:211:22:211:33 | object creation of type Object : Object | object creation of type Object : Object |
232254
| ExternalFlow.cs:240:18:240:18 | access to local variable o | ExternalFlow.cs:238:21:238:28 | object creation of type HC : HC | ExternalFlow.cs:240:18:240:18 | access to local variable o | $@ | ExternalFlow.cs:238:21:238:28 | object creation of type HC : HC | object creation of type HC : HC |
233255
| ExternalFlow.cs:258:18:258:18 | access to local variable b | ExternalFlow.cs:256:20:256:31 | object creation of type Object : Object | ExternalFlow.cs:258:18:258:18 | access to local variable b | $@ | ExternalFlow.cs:256:20:256:31 | object creation of type Object : Object | object creation of type Object : Object |
256+
| ExternalFlow.cs:281:18:281:27 | access to property Prop1 | ExternalFlow.cs:278:21:278:32 | object creation of type Object : Object | ExternalFlow.cs:281:18:281:27 | access to property Prop1 | $@ | ExternalFlow.cs:278:21:278:32 | object creation of type Object : Object | object creation of type Object : Object |
257+
| ExternalFlow.cs:289:18:289:27 | access to property Prop2 | ExternalFlow.cs:286:21:286:32 | object creation of type Object : Object | ExternalFlow.cs:289:18:289:27 | access to property Prop2 | $@ | ExternalFlow.cs:286:21:286:32 | object creation of type Object : Object | object creation of type Object : Object |

csharp/ql/test/library-tests/dataflow/external-models/ExternalFlow.ext.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,10 @@ extensions:
3333
- ["My.Qltest", "Library", false, "GeneratedFlowWithManualNeutral", "(System.Object)", "", "Argument[0]", "ReturnValue", "value", "df-generated"]
3434
- ["My.Qltest", "HE", false, "ExtensionMethod", "(My.Qltest.HI)", "", "Argument[0]", "ReturnValue", "value", "manual"]
3535
- ["My.Qltest", "I", false, "GetFirst", "(My.Qltest.MyInlineArray)", "", "Argument[0].Element", "ReturnValue", "value", "manual"]
36+
- ["My.Qltest", "J", false, "get_Prop1", "()", "", "Argument[this]", "ReturnValue", "value", "manual"]
37+
- ["My.Qltest", "J", false, "SetProp1", "(System.Object)", "", "Argument[0]", "Argument[this]", "value", "manual"]
38+
- ["My.Qltest", "J", false, "get_Prop2", "()", "", "Argument[this]", "ReturnValue", "value", "df-generated"]
39+
- ["My.Qltest", "J", false, "SetProp2", "(System.Object)", "", "Argument[0]", "Argument[this]", "value", "manual"]
3640
- addsTo:
3741
pack: codeql/csharp-all
3842
extensible: neutralModel

csharp/ql/test/utils/modelgenerator/dataflow/Summaries.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -575,3 +575,4 @@ public class DImpl : D
575575
public override string Prop { get { return tainted; } }
576576
}
577577
}
578+

0 commit comments

Comments
 (0)