Skip to content

Commit 4123876

Browse files
committed
C#: Add content based summary generation test.
1 parent 486246c commit 4123876

File tree

4 files changed

+76
-6
lines changed

4 files changed

+76
-6
lines changed
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
unexpectedModel
2+
expectedModel
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
extensions:
2+
- addsTo:
3+
pack: codeql/csharp-all
4+
extensible: summaryModel
5+
data:
6+
- [ "Models", "ManuallyModelled", False, "HasSummary", "(System.Object)", "", "Argument[0]", "ReturnValue", "value", "manual"]
7+
8+
- addsTo:
9+
pack: codeql/csharp-all
10+
extensible: neutralModel
11+
data:
12+
- [ "Models", "ManuallyModelled", "HasNeutralSummary", "(System.Object)", "summary", "manual"]
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
import csharp
2+
import utils.modelgenerator.internal.CaptureModels
3+
import TestUtilities.InlineMadTest
4+
5+
module InlineMadTestConfig implements InlineMadTestConfigSig {
6+
string getCapturedModel(Callable c) { result = captureContentFlow(c) }
7+
8+
string getKind() { result = "contentbased-summary" }
9+
}
10+
11+
import InlineMadTest<InlineMadTestConfig>

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

Lines changed: 51 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,43 +13,51 @@ public class BasicFlow
1313
private string tainted;
1414

1515
// summary=Models;BasicFlow;false;ReturnThis;(System.Object);;Argument[this];ReturnValue;value;df-generated
16+
// contentbased-summary=Models;BasicFlow;false;ReturnThis;(System.Object);;Argument[this];ReturnValue;value;df-generated
1617
public BasicFlow ReturnThis(object input)
1718
{
1819
return this;
1920
}
2021

2122
// summary=Models;BasicFlow;false;ReturnParam0;(System.String,System.Object);;Argument[0];ReturnValue;taint;df-generated
23+
// contentbased-summary=Models;BasicFlow;false;ReturnParam0;(System.String,System.Object);;Argument[0];ReturnValue;value;df-generated
2224
public string ReturnParam0(string input0, object input1)
2325
{
2426
return input0;
2527
}
2628

2729
// summary=Models;BasicFlow;false;ReturnParam1;(System.String,System.Object);;Argument[1];ReturnValue;taint;df-generated
30+
// contentbased-summary=Models;BasicFlow;false;ReturnParam1;(System.String,System.Object);;Argument[1];ReturnValue;value;df-generated
2831
public object ReturnParam1(string input0, object input1)
2932
{
3033
return input1;
3134
}
3235

3336
// summary=Models;BasicFlow;false;ReturnParamMultiple;(System.Object,System.Object);;Argument[0];ReturnValue;taint;df-generated
3437
// summary=Models;BasicFlow;false;ReturnParamMultiple;(System.Object,System.Object);;Argument[1];ReturnValue;taint;df-generated
38+
// contentbased-summary=Models;BasicFlow;false;ReturnParamMultiple;(System.Object,System.Object);;Argument[0];ReturnValue;value;df-generated
39+
// contentbased-summary=Models;BasicFlow;false;ReturnParamMultiple;(System.Object,System.Object);;Argument[1];ReturnValue;value;df-generated
3540
public object ReturnParamMultiple(object input0, object input1)
3641
{
3742
return (System.DateTime.Now.DayOfWeek == System.DayOfWeek.Monday) ? input0 : input1;
3843
}
3944

4045
// summary=Models;BasicFlow;false;ReturnSubstring;(System.String);;Argument[0];ReturnValue;taint;df-generated
46+
// contentbased-summary=Models;BasicFlow;false;ReturnSubstring;(System.String);;Argument[0];ReturnValue;taint;df-generated
4147
public string ReturnSubstring(string s)
4248
{
4349
return s.Substring(0, 1);
4450
}
4551

4652
// summary=Models;BasicFlow;false;SetField;(System.String);;Argument[0];Argument[this];taint;df-generated
53+
// contentbased-summary=Models;BasicFlow;false;SetField;(System.String);;Argument[0];Argument[this].SyntheticField[Models.BasicFlow.tainted];value;df-generated
4754
public void SetField(string s)
4855
{
4956
tainted = s;
5057
}
5158

5259
// summary=Models;BasicFlow;false;ReturnField;();;Argument[this];ReturnValue;taint;df-generated
60+
// contentbased-summary=Models;BasicFlow;false;ReturnField;();;Argument[this].SyntheticField[Models.BasicFlow.tainted];ReturnValue;value;df-generated
5361
public string ReturnField()
5462
{
5563
return tainted;
@@ -61,72 +69,84 @@ public class CollectionFlow
6169
private string tainted;
6270

6371
// summary=Models;CollectionFlow;false;ReturnArrayElement;(System.Object[]);;Argument[0].Element;ReturnValue;taint;df-generated
72+
// contentbased-summary=Models;CollectionFlow;false;ReturnArrayElement;(System.Object[]);;Argument[0].Element;ReturnValue;value;df-generated
6473
public object ReturnArrayElement(object[] input)
6574
{
6675
return input[0];
6776
}
6877

6978
// summary=Models;CollectionFlow;false;AssignToArray;(System.Object,System.Object[]);;Argument[0];Argument[1].Element;taint;df-generated
79+
// contentbased-summary=Models;CollectionFlow;false;AssignToArray;(System.Object,System.Object[]);;Argument[0];Argument[1].Element;value;df-generated
7080
public void AssignToArray(object data, object[] target)
7181
{
7282
target[0] = data;
7383
}
7484

7585
// summary=Models;CollectionFlow;false;AssignFieldToArray;(System.Object[]);;Argument[this];Argument[0].Element;taint;df-generated
86+
// contentbased-summary=Models;CollectionFlow;false;AssignFieldToArray;(System.Object[]);;Argument[this].SyntheticField[Models.CollectionFlow.tainted];Argument[0].Element;value;df-generated
7687
public void AssignFieldToArray(object[] target)
7788
{
7889
target[0] = tainted;
7990
}
8091

8192
// summary=Models;CollectionFlow;false;ReturnListElement;(System.Collections.Generic.List<System.Object>);;Argument[0].Element;ReturnValue;taint;df-generated
93+
// contentbased-summary=Models;CollectionFlow;false;ReturnListElement;(System.Collections.Generic.List<System.Object>);;Argument[0].Element;ReturnValue;value;df-generated
8294
public object ReturnListElement(List<object> input)
8395
{
8496
return input[0];
8597
}
8698

8799
// summary=Models;CollectionFlow;false;AddToList;(System.Collections.Generic.List<System.Object>,System.Object);;Argument[1];Argument[0].Element;taint;df-generated
100+
// contentbased-summary=Models;CollectionFlow;false;AddToList;(System.Collections.Generic.List<System.Object>,System.Object);;Argument[1];Argument[0].Element;value;df-generated
88101
public void AddToList(List<object> input, object data)
89102
{
90103
input.Add(data);
91104
}
92105

93106
// summary=Models;CollectionFlow;false;AddFieldToList;(System.Collections.Generic.List<System.String>);;Argument[this];Argument[0].Element;taint;df-generated
107+
// contentbased-summary=Models;CollectionFlow;false;AddFieldToList;(System.Collections.Generic.List<System.String>);;Argument[this].SyntheticField[Models.CollectionFlow.tainted];Argument[0].Element;value;df-generated
94108
public void AddFieldToList(List<string> input)
95109
{
96110
input.Add(tainted);
97111
}
98112

99113
// summary=Models;CollectionFlow;false;ReturnFieldInAList;();;Argument[this];ReturnValue;taint;df-generated
114+
// contentbased-summary=Models;CollectionFlow;false;ReturnFieldInAList;();;Argument[this].SyntheticField[Models.CollectionFlow.tainted];ReturnValue.Element;value;df-generated
100115
public List<string> ReturnFieldInAList()
101116
{
102117
return new List<string> { tainted };
103118
}
104119

105-
// summary=Models;CollectionFlow;false;ReturnComplexTypeArray;(System.String[]);;Argument[0].Element;ReturnValue;taint;df-generated
120+
// SPURIOUS-summary=Models;CollectionFlow;false;ReturnComplexTypeArray;(System.String[]);;Argument[0].Element;ReturnValue;taint;df-generated
121+
// contentbased-summary=Models;CollectionFlow;false;ReturnComplexTypeArray;(System.String[]);;Argument[0];ReturnValue;value;df-generated
106122
public string[] ReturnComplexTypeArray(string[] a)
107123
{
108124
return a;
109125
}
110126

111-
// summary=Models;CollectionFlow;false;ReturnBulkTypeList;(System.Collections.Generic.List<System.Byte>);;Argument[0].Element;ReturnValue;taint;df-generated
127+
// SPURIOUS-summary=Models;CollectionFlow;false;ReturnBulkTypeList;(System.Collections.Generic.List<System.Byte>);;Argument[0].Element;ReturnValue;taint;df-generated
128+
// contentbased-summary=Models;CollectionFlow;false;ReturnBulkTypeList;(System.Collections.Generic.List<System.Byte>);;Argument[0];ReturnValue;value;df-generated
112129
public List<byte> ReturnBulkTypeList(List<byte> a)
113130
{
114131
return a;
115132
}
116133

117-
// summary=Models;CollectionFlow;false;ReturnComplexTypeDictionary;(System.Collections.Generic.Dictionary<System.Int32,System.String>);;Argument[0].Element;ReturnValue;taint;df-generated
134+
// SPURIOUS-summary=Models;CollectionFlow;false;ReturnComplexTypeDictionary;(System.Collections.Generic.Dictionary<System.Int32,System.String>);;Argument[0].Element;ReturnValue;taint;df-generated
135+
// contentbased-summary=Models;CollectionFlow;false;ReturnComplexTypeDictionary;(System.Collections.Generic.Dictionary<System.Int32,System.String>);;Argument[0];ReturnValue;value;df-generated
118136
public Dictionary<int, string> ReturnComplexTypeDictionary(Dictionary<int, string> a)
119137
{
120138
return a;
121139
}
122140

123-
// summary=Models;CollectionFlow;false;ReturnUntypedArray;(System.Array);;Argument[0].Element;ReturnValue;taint;df-generated
141+
// SPURIOUS-summary=Models;CollectionFlow;false;ReturnUntypedArray;(System.Array);;Argument[0].Element;ReturnValue;taint;df-generated
142+
// contentbased-summary=Models;CollectionFlow;false;ReturnUntypedArray;(System.Array);;Argument[0];ReturnValue;value;df-generated
124143
public Array ReturnUntypedArray(Array a)
125144
{
126145
return a;
127146
}
128147

129-
// summary=Models;CollectionFlow;false;ReturnUntypedList;(System.Collections.IList);;Argument[0].Element;ReturnValue;taint;df-generated
148+
// SPURIOUS-summary=Models;CollectionFlow;false;ReturnUntypedList;(System.Collections.IList);;Argument[0].Element;ReturnValue;taint;df-generated
149+
// contentbased-summary=Models;CollectionFlow;false;ReturnUntypedList;(System.Collections.IList);;Argument[0];ReturnValue;value;df-generated
130150
public IList ReturnUntypedList(IList a)
131151
{
132152
return a;
@@ -159,19 +179,22 @@ public class IEnumerableFlow
159179
{
160180
private string tainted;
161181

162-
// summary=Models;IEnumerableFlow;false;ReturnIEnumerable;(System.Collections.Generic.IEnumerable<System.String>);;Argument[0].Element;ReturnValue;taint;df-generated
182+
// SPURIOUS-summary=Models;IEnumerableFlow;false;ReturnIEnumerable;(System.Collections.Generic.IEnumerable<System.String>);;Argument[0].Element;ReturnValue;taint;df-generated
183+
// contentbased-summary=Models;IEnumerableFlow;false;ReturnIEnumerable;(System.Collections.Generic.IEnumerable<System.String>);;Argument[0];ReturnValue;value;df-generated
163184
public IEnumerable<string> ReturnIEnumerable(IEnumerable<string> input)
164185
{
165186
return input;
166187
}
167188

168189
// summary=Models;IEnumerableFlow;false;ReturnIEnumerableElement;(System.Collections.Generic.IEnumerable<System.Object>);;Argument[0].Element;ReturnValue;taint;df-generated
190+
// contentbased-summary=Models;IEnumerableFlow;false;ReturnIEnumerableElement;(System.Collections.Generic.IEnumerable<System.Object>);;Argument[0].Element;ReturnValue;value;df-generated
169191
public object ReturnIEnumerableElement(IEnumerable<object> input)
170192
{
171193
return input.First();
172194
}
173195

174196
// summary=Models;IEnumerableFlow;false;ReturnFieldInIEnumerable;();;Argument[this];ReturnValue;taint;df-generated
197+
// contentbased-summary=Models;IEnumerableFlow;false;ReturnFieldInIEnumerable;();;Argument[this].SyntheticField[Models.IEnumerableFlow.tainted];ReturnValue.Element;value;df-generated
175198
public IEnumerable<string> ReturnFieldInIEnumerable()
176199
{
177200
return new List<string> { tainted };
@@ -183,42 +206,49 @@ public class GenericFlow<T>
183206
private T tainted;
184207

185208
// summary=Models;GenericFlow<T>;false;SetGenericField;(T);;Argument[0];Argument[this];taint;df-generated
209+
// contentbased-summary=Models;GenericFlow<T>;false;SetGenericField;(T);;Argument[0];Argument[this].SyntheticField[Models.GenericFlow`1.tainted];value;df-generated
186210
public void SetGenericField(T t)
187211
{
188212
tainted = t;
189213
}
190214

191215
// summary=Models;GenericFlow<T>;false;ReturnGenericField;();;Argument[this];ReturnValue;taint;df-generated
216+
// contentbased-summary=Models;GenericFlow<T>;false;ReturnGenericField;();;Argument[this].SyntheticField[Models.GenericFlow`1.tainted];ReturnValue;value;df-generated
192217
public T ReturnGenericField()
193218
{
194219
return tainted;
195220
}
196221

197222
// summary=Models;GenericFlow<T>;false;AddFieldToGenericList;(System.Collections.Generic.List<T>);;Argument[this];Argument[0].Element;taint;df-generated
223+
// contentbased-summary=Models;GenericFlow<T>;false;AddFieldToGenericList;(System.Collections.Generic.List<T>);;Argument[this].SyntheticField[Models.GenericFlow`1.tainted];Argument[0].Element;value;df-generated
198224
public void AddFieldToGenericList(List<T> input)
199225
{
200226
input.Add(tainted);
201227
}
202228

203229
// summary=Models;GenericFlow<T>;false;ReturnFieldInGenericList;();;Argument[this];ReturnValue;taint;df-generated
230+
// contentbased-summary=Models;GenericFlow<T>;false;ReturnFieldInGenericList;();;Argument[this].SyntheticField[Models.GenericFlow`1.tainted];ReturnValue.Element;value;df-generated
204231
public List<T> ReturnFieldInGenericList()
205232
{
206233
return new List<T> { tainted };
207234
}
208235

209236
// summary=Models;GenericFlow<T>;false;ReturnGenericParam<S>;(S);;Argument[0];ReturnValue;taint;df-generated
237+
// contentbased-summary=Models;GenericFlow<T>;false;ReturnGenericParam<S>;(S);;Argument[0];ReturnValue;value;df-generated
210238
public S ReturnGenericParam<S>(S input)
211239
{
212240
return input;
213241
}
214242

215243
// summary=Models;GenericFlow<T>;false;ReturnGenericElement<S>;(System.Collections.Generic.List<S>);;Argument[0].Element;ReturnValue;taint;df-generated
244+
// contentbased-summary=Models;GenericFlow<T>;false;ReturnGenericElement<S>;(System.Collections.Generic.List<S>);;Argument[0].Element;ReturnValue;value;df-generated
216245
public S ReturnGenericElement<S>(List<S> input)
217246
{
218247
return input[0];
219248
}
220249

221250
// summary=Models;GenericFlow<T>;false;AddToGenericList<S>;(System.Collections.Generic.List<S>,S);;Argument[1];Argument[0].Element;taint;df-generated
251+
// contentbased-summary=Models;GenericFlow<T>;false;AddToGenericList<S>;(System.Collections.Generic.List<S>,S);;Argument[1];Argument[0].Element;value;df-generated
222252
public void AddToGenericList<S>(List<S> input, S data)
223253
{
224254
input.Add(data);
@@ -228,6 +258,7 @@ public void AddToGenericList<S>(List<S> input, S data)
228258
public abstract class BaseClassFlow
229259
{
230260
// summary=Models;BaseClassFlow;true;ReturnParam;(System.Object);;Argument[0];ReturnValue;taint;df-generated
261+
// contentbased-summary=Models;BaseClassFlow;true;ReturnParam;(System.Object);;Argument[0];ReturnValue;value;df-generated
231262
public virtual object ReturnParam(object input)
232263
{
233264
return input;
@@ -237,6 +268,7 @@ public virtual object ReturnParam(object input)
237268
public class DerivedClass1Flow : BaseClassFlow
238269
{
239270
// summary=Models;DerivedClass1Flow;false;ReturnParam1;(System.String,System.String);;Argument[1];ReturnValue;taint;df-generated
271+
// contentbased-summary=Models;DerivedClass1Flow;false;ReturnParam1;(System.String,System.String);;Argument[1];ReturnValue;value;df-generated
240272
public string ReturnParam1(string input0, string input1)
241273
{
242274
return input1;
@@ -246,12 +278,14 @@ public string ReturnParam1(string input0, string input1)
246278
public class DerivedClass2Flow : BaseClassFlow
247279
{
248280
// summary=Models;BaseClassFlow;true;ReturnParam;(System.Object);;Argument[0];ReturnValue;taint;df-generated
281+
// contentbased-summary=Models;BaseClassFlow;true;ReturnParam;(System.Object);;Argument[0];ReturnValue;value;df-generated
249282
public override object ReturnParam(object input)
250283
{
251284
return input;
252285
}
253286

254287
// summary=Models;DerivedClass2Flow;false;ReturnParam0;(System.String,System.Int32);;Argument[0];ReturnValue;taint;df-generated
288+
// contentbased-summary=Models;DerivedClass2Flow;false;ReturnParam0;(System.String,System.Int32);;Argument[0];ReturnValue;value;df-generated
255289
public string ReturnParam0(string input0, int input1)
256290
{
257291
return input0;
@@ -263,13 +297,15 @@ public class OperatorFlow
263297
public readonly object Field;
264298

265299
// summary=Models;OperatorFlow;false;OperatorFlow;(System.Object);;Argument[0];Argument[this];taint;df-generated
300+
// contentbased-summary=Models;OperatorFlow;false;OperatorFlow;(System.Object);;Argument[0];Argument[this].Field[Models.OperatorFlow.Field];value;df-generated
266301
public OperatorFlow(object o)
267302
{
268303
Field = o;
269304
}
270305

271306
// Flow Summary.
272307
// summary=Models;OperatorFlow;false;op_Addition;(Models.OperatorFlow,Models.OperatorFlow);;Argument[0];ReturnValue;taint;df-generated
308+
// contentbased-summary=Models;OperatorFlow;false;op_Addition;(Models.OperatorFlow,Models.OperatorFlow);;Argument[0];ReturnValue;value;df-generated
273309
public static OperatorFlow operator +(OperatorFlow a, OperatorFlow b)
274310
{
275311
return a;
@@ -310,6 +346,7 @@ public override bool Equals(object obj)
310346
}
311347

312348
// summary=Models;EqualsGetHashCodeNoFlow;false;Equals;(System.String);;Argument[0];ReturnValue;taint;df-generated
349+
// contentbased-summary=Models;EqualsGetHashCodeNoFlow;false;Equals;(System.String);;Argument[0];ReturnValue;value;df-generated
313350
public string Equals(string s)
314351
{
315352
return s;
@@ -327,12 +364,14 @@ public class Properties
327364
private string tainted;
328365

329366
// summary=Models;Properties;false;get_Prop1;();;Argument[this];ReturnValue;taint;df-generated
367+
// contentbased-summary=Models;Properties;false;get_Prop1;();;Argument[this].SyntheticField[Models.Properties.tainted];ReturnValue;value;df-generated
330368
public string Prop1
331369
{
332370
get { return tainted; }
333371
}
334372

335373
// summary=Models;Properties;false;set_Prop2;(System.String);;Argument[0];Argument[this];taint;df-generated
374+
// contentbased-summary=Models;Properties;false;set_Prop2;(System.String);;Argument[0];Argument[this].SyntheticField[Models.Properties.tainted];value;df-generated
336375
public string Prop2
337376
{
338377
set { tainted = value; }
@@ -513,6 +552,7 @@ public abstract class BasePublic
513552
public class AImplBasePublic : BasePublic
514553
{
515554
// summary=Models;Inheritance+BasePublic;true;Id;(System.String);;Argument[0];ReturnValue;taint;df-generated
555+
// contentbased-summary=Models;Inheritance+BasePublic;true;Id;(System.String);;Argument[0];ReturnValue;value;df-generated
516556
public override string Id(string x)
517557
{
518558
return x;
@@ -542,6 +582,7 @@ private abstract class C : IPublic2
542582
public class BImpl : B
543583
{
544584
// summary=Models;Inheritance+IPublic1;true;Id;(System.String);;Argument[0];ReturnValue;taint;df-generated
585+
// contentbased-summary=Models;Inheritance+IPublic1;true;Id;(System.String);;Argument[0];ReturnValue;value;df-generated
545586
public override string Id(string x)
546587
{
547588
return x;
@@ -551,6 +592,7 @@ public override string Id(string x)
551592
private class CImpl : C
552593
{
553594
// summary=Models;Inheritance+IPublic2;true;Id;(System.String);;Argument[0];ReturnValue;taint;df-generated
595+
// contentbased-summary=Models;Inheritance+IPublic2;true;Id;(System.String);;Argument[0];ReturnValue;value;df-generated
554596
public override string Id(string x)
555597
{
556598
return x;
@@ -572,6 +614,7 @@ public class DImpl : D
572614
private string tainted;
573615

574616
// summary=Models;Inheritance+IPublic3;true;get_Prop;();;Argument[this];ReturnValue;taint;df-generated
617+
// contentbased-summary=Models;Inheritance+IPublic3;true;get_Prop;();;Argument[this].SyntheticField[Models.Inheritance+DImpl.tainted];ReturnValue;value;df-generated
575618
public override string Prop { get { return tainted; } }
576619
}
577620
}
@@ -586,12 +629,14 @@ public class C
586629
}
587630

588631
// summary=Models;MemberFlow;false;M1;(Models.MemberFlow+C);;Argument[0];ReturnValue;taint;df-generated
632+
// contentbased-summary=Models;MemberFlow;false;M1;(Models.MemberFlow+C);;Argument[0].Property[Models.MemberFlow+C.Prop];ReturnValue;value;df-generated
589633
public string M1(C c)
590634
{
591635
return c.Prop;
592636
}
593637

594638
// summary=Models;MemberFlow;false;M2;(Models.MemberFlow+C);;Argument[0];ReturnValue;taint;df-generated
639+
// contentbased-summary=Models;MemberFlow;false;M2;(Models.MemberFlow+C);;Argument[0].Field[Models.MemberFlow+C.Field];ReturnValue;value;df-generated
595640
public string M2(C c)
596641
{
597642
return c.Field;

0 commit comments

Comments
 (0)