Skip to content

Commit 370a32d

Browse files
committed
Test summary models and neutral models, manual and generated
1 parent 28aa9b2 commit 370a32d

File tree

10 files changed

+93
-15
lines changed

10 files changed

+93
-15
lines changed

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

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -206,12 +206,25 @@ void M3()
206206
Sink(MixedFlowArgs(null, o2));
207207
}
208208

209+
void M4()
210+
{
211+
var o1 = new object();
212+
Sink(GeneratedFlowWithGeneratedNeutral(o1));
213+
214+
var o2 = new object();
215+
Sink(GeneratedFlowWithManualNeutral(o2)); // no flow because the modelled method exists has a manual neutral summary model
216+
}
217+
209218
object GeneratedFlow(object o) => throw null;
210219

211220
object GeneratedFlowArgs(object o1, object o2) => throw null;
212221

213222
object MixedFlowArgs(object o1, object o2) => throw null;
214223

224+
object GeneratedFlowWithGeneratedNeutral(object o) => throw null;
225+
226+
object GeneratedFlowWithManualNeutral(object o) => throw null;
227+
215228
static void Sink(object o) { }
216229
}
217230

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

Lines changed: 20 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -63,9 +63,13 @@ edges
6363
| ExternalFlow.cs:120:18:120:18 | access to local variable b : null [element] : Object | ExternalFlow.cs:120:18:120:21 | access to array element |
6464
| ExternalFlow.cs:205:22:205:33 | object creation of type Object : Object | ExternalFlow.cs:206:38:206:39 | access to local variable o2 : Object |
6565
| ExternalFlow.cs:206:38:206:39 | access to local variable o2 : Object | ExternalFlow.cs:206:18:206:40 | call to method MixedFlowArgs |
66-
| ExternalFlow.cs:231:21:231:28 | object creation of type HC : HC | ExternalFlow.cs:232:21:232:21 | access to local variable h : HC |
67-
| ExternalFlow.cs:232:21:232:21 | access to local variable h : HC | ExternalFlow.cs:232:21:232:39 | call to method ExtensionMethod : HC |
68-
| ExternalFlow.cs:232:21:232:39 | call to method ExtensionMethod : HC | ExternalFlow.cs:233:18:233:18 | access to local variable o |
66+
| ExternalFlow.cs:211:22:211:33 | object creation of type Object : Object | ExternalFlow.cs:212:52:212:53 | access to local variable o1 : Object |
67+
| ExternalFlow.cs:212:52:212:53 | access to local variable o1 : Object | ExternalFlow.cs:212:18:212:54 | call to method GeneratedFlowWithGeneratedNeutral |
68+
| ExternalFlow.cs:214:22:214:33 | object creation of type Object : Object | ExternalFlow.cs:215:49:215:50 | access to local variable o2 : Object |
69+
| ExternalFlow.cs:215:49:215:50 | access to local variable o2 : Object | ExternalFlow.cs:215:18:215:51 | call to method GeneratedFlowWithManualNeutral |
70+
| ExternalFlow.cs:244:21:244:28 | object creation of type HC : HC | ExternalFlow.cs:245:21:245:21 | access to local variable h : HC |
71+
| ExternalFlow.cs:245:21:245:21 | access to local variable h : HC | ExternalFlow.cs:245:21:245:39 | call to method ExtensionMethod : HC |
72+
| ExternalFlow.cs:245:21:245:39 | call to method ExtensionMethod : HC | ExternalFlow.cs:246:18:246:18 | access to local variable o |
6973
nodes
7074
| ExternalFlow.cs:9:27:9:38 | object creation of type Object : Object | semmle.label | object creation of type Object : Object |
7175
| ExternalFlow.cs:10:18:10:33 | call to method StepArgRes | semmle.label | call to method StepArgRes |
@@ -148,10 +152,16 @@ nodes
148152
| ExternalFlow.cs:205:22:205:33 | object creation of type Object : Object | semmle.label | object creation of type Object : Object |
149153
| ExternalFlow.cs:206:18:206:40 | call to method MixedFlowArgs | semmle.label | call to method MixedFlowArgs |
150154
| ExternalFlow.cs:206:38:206:39 | access to local variable o2 : Object | semmle.label | access to local variable o2 : Object |
151-
| ExternalFlow.cs:231:21:231:28 | object creation of type HC : HC | semmle.label | object creation of type HC : HC |
152-
| ExternalFlow.cs:232:21:232:21 | access to local variable h : HC | semmle.label | access to local variable h : HC |
153-
| ExternalFlow.cs:232:21:232:39 | call to method ExtensionMethod : HC | semmle.label | call to method ExtensionMethod : HC |
154-
| ExternalFlow.cs:233:18:233:18 | access to local variable o | semmle.label | access to local variable o |
155+
| ExternalFlow.cs:211:22:211:33 | object creation of type Object : Object | semmle.label | object creation of type Object : Object |
156+
| ExternalFlow.cs:212:18:212:54 | call to method GeneratedFlowWithGeneratedNeutral | semmle.label | call to method GeneratedFlowWithGeneratedNeutral |
157+
| ExternalFlow.cs:212:52:212:53 | access to local variable o1 : Object | semmle.label | access to local variable o1 : Object |
158+
| ExternalFlow.cs:214:22:214:33 | object creation of type Object : Object | semmle.label | object creation of type Object : Object |
159+
| ExternalFlow.cs:215:18:215:51 | call to method GeneratedFlowWithManualNeutral | semmle.label | call to method GeneratedFlowWithManualNeutral |
160+
| ExternalFlow.cs:215:49:215:50 | access to local variable o2 : Object | semmle.label | access to local variable o2 : Object |
161+
| ExternalFlow.cs:244:21:244:28 | object creation of type HC : HC | semmle.label | object creation of type HC : HC |
162+
| ExternalFlow.cs:245:21:245:21 | access to local variable h : HC | semmle.label | access to local variable h : HC |
163+
| ExternalFlow.cs:245:21:245:39 | call to method ExtensionMethod : HC | semmle.label | call to method ExtensionMethod : HC |
164+
| ExternalFlow.cs:246:18:246:18 | access to local variable o | semmle.label | access to local variable o |
155165
subpaths
156166
#select
157167
| ExternalFlow.cs:10:18:10:33 | call to method StepArgRes | ExternalFlow.cs:9:27:9:38 | object creation of type Object : Object | ExternalFlow.cs:10:18:10:33 | call to method StepArgRes | $@ | ExternalFlow.cs:9:27:9:38 | object creation of type Object : Object | object creation of type Object : Object |
@@ -175,4 +185,6 @@ subpaths
175185
| ExternalFlow.cs:112:18:112:25 | access to property MyProp | ExternalFlow.cs:111:24:111:35 | object creation of type Object : Object | ExternalFlow.cs:112:18:112:25 | access to property MyProp | $@ | ExternalFlow.cs:111:24:111:35 | object creation of type Object : Object | object creation of type Object : Object |
176186
| ExternalFlow.cs:120:18:120:21 | access to array element | ExternalFlow.cs:117:36:117:47 | object creation of type Object : Object | ExternalFlow.cs:120:18:120:21 | access to array element | $@ | ExternalFlow.cs:117:36:117:47 | object creation of type Object : Object | object creation of type Object : Object |
177187
| ExternalFlow.cs:206:18:206:40 | call to method MixedFlowArgs | ExternalFlow.cs:205:22:205:33 | object creation of type Object : Object | ExternalFlow.cs:206:18:206:40 | call to method MixedFlowArgs | $@ | ExternalFlow.cs:205:22:205:33 | object creation of type Object : Object | object creation of type Object : Object |
178-
| ExternalFlow.cs:233:18:233:18 | access to local variable o | ExternalFlow.cs:231:21:231:28 | object creation of type HC : HC | ExternalFlow.cs:233:18:233:18 | access to local variable o | $@ | ExternalFlow.cs:231:21:231:28 | object creation of type HC : HC | object creation of type HC : HC |
188+
| ExternalFlow.cs:212:18:212:54 | call to method GeneratedFlowWithGeneratedNeutral | ExternalFlow.cs:211:22:211:33 | object creation of type Object : Object | ExternalFlow.cs:212:18:212:54 | call to method GeneratedFlowWithGeneratedNeutral | $@ | ExternalFlow.cs:211:22:211:33 | object creation of type Object : Object | object creation of type Object : Object |
189+
| ExternalFlow.cs:215:18:215:51 | call to method GeneratedFlowWithManualNeutral | ExternalFlow.cs:214:22:214:33 | object creation of type Object : Object | ExternalFlow.cs:215:18:215:51 | call to method GeneratedFlowWithManualNeutral | $@ | ExternalFlow.cs:214:22:214:33 | object creation of type Object : Object | object creation of type Object : Object |
190+
| ExternalFlow.cs:246:18:246:18 | access to local variable o | ExternalFlow.cs:244:21:244:28 | object creation of type HC : HC | ExternalFlow.cs:246:18:246:18 | access to local variable o | $@ | ExternalFlow.cs:244:21:244:28 | object creation of type HC : HC | object creation of type HC : HC |

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

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,4 +29,13 @@ extensions:
2929
- ["My.Qltest", "G", false, "GeneratedFlowArgs", "(System.Object,System.Object)", "", "Argument[1]", "ReturnValue", "value", "df-generated"]
3030
- ["My.Qltest", "G", false, "MixedFlowArgs", "(System.Object,System.Object)", "", "Argument[0]", "ReturnValue", "value", "df-generated"]
3131
- ["My.Qltest", "G", false, "MixedFlowArgs", "(System.Object,System.Object)", "", "Argument[1]", "ReturnValue", "value", "manual"]
32+
- ["My.Qltest", "G", false, "GeneratedFlowWithGeneratedNeutral", "(System.Object)", "", "Argument[0]", "ReturnValue", "value", "df-generated"]
33+
- ["My.Qltest", "G", false, "GeneratedFlowWithManualNeutral", "(System.Object)", "", "Argument[0]", "ReturnValue", "value", "df-generated"]
3234
- ["My.Qltest", "HE", false, "ExtensionMethod", "(My.Qltest.HI)", "", "Argument[0]", "ReturnValue", "value", "manual"]
35+
- addsTo:
36+
pack: codeql/csharp-all
37+
extensible: neutralModel
38+
# "namespace", "type", "name", "signature", "kind", "provenance"
39+
data:
40+
- ["My.Qltest", "G", "GeneratedFlowWithGeneratedNeutral", "(System.Object)", "summary", "df-generated"]
41+
- ["My.Qltest", "G", "GeneratedFlowWithManualNeutral", "(System.Object)", "summary", "manual"]

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

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,11 @@ module Taint = TaintTracking::Global<TaintConfig>;
2626
* provenance as generated summaries are only applied, if a
2727
* callable does not have a body.
2828
*/
29-
private class MixedFlowArgs extends Method {
30-
MixedFlowArgs() { this.hasFullyQualifiedName("My.Qltest", "G", "MixedFlowArgs") }
29+
private class MethodsWithGeneratedModels extends Method {
30+
MethodsWithGeneratedModels() {
31+
this.hasFullyQualifiedName("My.Qltest", "G",
32+
["MixedFlowArgs", "GeneratedFlowWithGeneratedNeutral", "GeneratedFlowWithManualNeutral"])
33+
}
3134

3235
override predicate hasBody() { none() }
3336
}

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

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,12 @@ void Foo()
4242
gen.StepGeneric2(false);
4343

4444
new Sub().StepOverride("string");
45+
46+
object arg4 = new object();
47+
this.StepArgQualGenerated(arg4);
48+
49+
object arg5 = new object();
50+
this.StepArgQualGeneratedIgnored(arg5);
4551
}
4652

4753
object StepArgRes(object x) { return null; }
@@ -50,6 +56,10 @@ void StepArgArg(object @in, object @out) { }
5056

5157
void StepArgQual(object x) { }
5258

59+
void StepArgQualGenerated(object x) { }
60+
61+
void StepArgQualGeneratedIgnored(object x) { }
62+
5363
object StepQualRes() { return null; }
5464

5565
void StepQualArg(object @out) { }
@@ -87,4 +97,4 @@ class Sub : Base<string>
8797
public override string StepOverride(string i) => throw null;
8898
}
8999
}
90-
}
100+
}

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

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,13 @@ summaryThroughStep
1111
| Steps.cs:41:29:41:29 | 0 | Steps.cs:41:13:41:30 | call to method StepGeneric | true |
1212
| Steps.cs:42:30:42:34 | false | Steps.cs:42:13:42:35 | call to method StepGeneric2<Boolean> | true |
1313
| Steps.cs:44:36:44:43 | "string" | Steps.cs:44:13:44:44 | call to method StepOverride | true |
14+
| Steps.cs:47:39:47:42 | access to local variable arg4 | Steps.cs:47:13:47:16 | [post] this access | false |
15+
| Steps.cs:50:46:50:49 | access to local variable arg5 | Steps.cs:50:13:50:16 | [post] this access | false |
1416
summaryGetterStep
15-
| Steps.cs:28:13:28:16 | this access | Steps.cs:28:13:28:34 | call to method StepFieldGetter | Steps.cs:57:13:57:17 | field Field |
16-
| Steps.cs:32:13:32:16 | this access | Steps.cs:32:13:32:37 | call to method StepPropertyGetter | Steps.cs:63:13:63:20 | property Property |
17+
| Steps.cs:28:13:28:16 | this access | Steps.cs:28:13:28:34 | call to method StepFieldGetter | Steps.cs:67:13:67:17 | field Field |
18+
| Steps.cs:32:13:32:16 | this access | Steps.cs:32:13:32:37 | call to method StepPropertyGetter | Steps.cs:73:13:73:20 | property Property |
1719
| Steps.cs:36:13:36:16 | this access | Steps.cs:36:13:36:36 | call to method StepElementGetter | file://:0:0:0:0 | element |
1820
summarySetterStep
19-
| Steps.cs:30:34:30:34 | 0 | Steps.cs:30:13:30:16 | [post] this access | Steps.cs:57:13:57:17 | field Field |
20-
| Steps.cs:34:37:34:37 | 0 | Steps.cs:34:13:34:16 | [post] this access | Steps.cs:63:13:63:20 | property Property |
21+
| Steps.cs:30:34:30:34 | 0 | Steps.cs:30:13:30:16 | [post] this access | Steps.cs:67:13:67:17 | field Field |
22+
| Steps.cs:34:37:34:37 | 0 | Steps.cs:34:13:34:16 | [post] this access | Steps.cs:73:13:73:20 | property Property |
2123
| Steps.cs:38:36:38:36 | 0 | Steps.cs:38:13:38:16 | [post] this access | file://:0:0:0:0 | element |

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

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,3 +18,13 @@ extensions:
1818
- ["My.Qltest", "C+Generic<T,U>", false, "StepGeneric", "(T)", "", "Argument[0]", "ReturnValue", "value", "manual"]
1919
- ["My.Qltest", "C+Generic<T,U>", false, "StepGeneric2<S>", "(S)", "", "Argument[0]", "ReturnValue", "value", "manual"]
2020
- ["My.Qltest", "C+Base<T>", true, "StepOverride", "(T)", "", "Argument[0]", "ReturnValue", "value", "manual"]
21+
- ["My.Qltest", "C", false, "StepArgQualGenerated", "(System.Object)", "", "Argument[0]", "Argument[this]", "taint", "df-generated"]
22+
- ["My.Qltest", "C", false, "StepArgQualGeneratedIgnored", "(System.Object)", "", "Argument[0]", "Argument[this]", "taint", "df-generated"]
23+
- addsTo:
24+
pack: codeql/csharp-all
25+
extensible: neutralModel
26+
# "namespace", "type", "name", "signature", "kind", "provenance"
27+
data:
28+
- ["My.Qltest", "C", "StepArgQualGenerated", "(System.Object)", "summary", "df-generated"]
29+
- ["My.Qltest", "C", "StepArgQualGeneratedIgnored", "(System.Object)", "summary", "manual"]
30+

java/ql/test/library-tests/dataflow/external-models/C.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,11 @@ void fooGenerated() {
3232
// The summary for the first parameter is ignored, because it is generated and
3333
// because there is hand written summary for the second parameter.
3434
stepArgResGeneratedIgnored(arg1, arg2);
35+
36+
stepArgQualGenerated(arg1);
37+
// The summary for the first parameter is ignored, because it is generated and
38+
// because there is hand written neutral summary model for this callable.
39+
stepArgQualGeneratedIgnored(arg1);
3540
}
3641

3742
Object stepArgRes(Object x) { return null; }
@@ -47,4 +52,8 @@ void stepQualArg(Object out) { }
4752
Object stepArgResGenerated(Object x) { return null; }
4853

4954
Object stepArgResGeneratedIgnored(Object x, Object y) { return null; }
55+
56+
Object stepArgQualGenerated(Object x) { return null; }
57+
58+
Object stepArgQualGeneratedIgnored(Object x) { return null; }
5059
}

java/ql/test/library-tests/dataflow/external-models/steps.expected

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,3 +10,5 @@ invalidModelRow
1010
| C.java:24:5:24:23 | this <.method> | C.java:24:17:24:22 | argOut [post update] |
1111
| C.java:29:25:29:28 | arg1 | C.java:29:5:29:29 | stepArgResGenerated(...) |
1212
| C.java:34:38:34:41 | arg2 | C.java:34:5:34:42 | stepArgResGeneratedIgnored(...) |
13+
| C.java:36:26:36:29 | arg1 | C.java:36:5:36:30 | this <.method> [post update] |
14+
| C.java:39:33:39:36 | arg1 | C.java:39:5:39:37 | this <.method> [post update] |

java/ql/test/library-tests/dataflow/external-models/steps.ext.yml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,3 +11,11 @@ extensions:
1111
- ["my.qltest", "C", False, "stepArgResGenerated", "(Object)", "", "Argument[0]", "ReturnValue", "taint", "df-generated"]
1212
- ["my.qltest", "C", False, "stepArgResGeneratedIgnored", "(Object,Object)", "", "Argument[0]", "ReturnValue", "taint", "df-generated"]
1313
- ["my.qltest", "C", False, "stepArgResGeneratedIgnored", "(Object,Object)", "", "Argument[1]", "ReturnValue", "taint", "manual"]
14+
- ["my.qltest", "C", False, "stepArgQualGenerated", "(Object)", "", "Argument[0]", "Argument[this]", "taint", "df-generated"]
15+
- ["my.qltest", "C", False, "stepArgQualGeneratedIgnored", "(Object)", "", "Argument[0]", "Argument[this]", "taint", "df-generated"]
16+
- addsTo:
17+
pack: codeql/java-all
18+
extensible: neutralModel
19+
data:
20+
- ["my.qltest", "C", "stepArgQualGenerated", "(Object)", "summary", "df-generated"]
21+
- ["my.qltest", "C", "stepArgQualGeneratedIgnored", "(Object)", "summary", "manual"]

0 commit comments

Comments
 (0)