Skip to content

Commit 7761774

Browse files
committed
Add record .ctor to property data flow summary
1 parent 6a6644b commit 7761774

File tree

3 files changed

+27
-8
lines changed

3 files changed

+27
-8
lines changed

csharp/ql/src/semmle/code/csharp/dataflow/LibraryTypeDataFlow.qll

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2416,3 +2416,22 @@ class StringValuesFlow extends LibraryTypeDataFlow, Struct {
24162416
preservesValue = false
24172417
}
24182418
}
2419+
2420+
private class RecordConstructorFlow extends SummarizedCallable {
2421+
RecordConstructorFlow() { this = any(Record r).getAMember().(Constructor) }
2422+
2423+
override predicate propagatesFlow(
2424+
SummaryInput input, ContentList inputContents, SummaryOutput output, ContentList outputContents,
2425+
boolean preservesValue
2426+
) {
2427+
exists(int i, Property p, string name |
2428+
this.getParameter(i).getName() = name and
2429+
this.getDeclaringType().getAMember(name) = p and
2430+
input = SummaryInput::parameter(i) and
2431+
inputContents = ContentList::empty() and
2432+
output = SummaryOutput::return() and
2433+
outputContents = ContentList::property(p) and
2434+
preservesValue = true
2435+
)
2436+
}
2437+
}

csharp/ql/test/library-tests/dataflow/fields/FieldFlow.expected

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -238,12 +238,12 @@ edges
238238
| I.cs:37:23:37:23 | i [Field1] : Object | I.cs:39:9:39:9 | access to parameter i [Field1] : Object |
239239
| I.cs:39:9:39:9 | access to parameter i [Field1] : Object | I.cs:40:14:40:14 | access to parameter i [Field1] : Object |
240240
| I.cs:40:14:40:14 | access to parameter i [Field1] : Object | I.cs:40:14:40:21 | access to field Field1 |
241-
| J.cs:12:17:12:28 | object creation of type Object : Object | J.cs:13:48:13:48 | access to local variable o : Object |
241+
| J.cs:12:17:12:28 | object creation of type Object : Object | J.cs:13:29:13:29 | access to local variable o : Object |
242242
| J.cs:12:17:12:28 | object creation of type Object : Object | J.cs:21:36:21:36 | access to local variable o : Object |
243-
| J.cs:13:38:13:50 | { ..., ... } [Prop1] : Object | J.cs:14:14:14:15 | access to local variable r1 [Prop1] : Object |
244-
| J.cs:13:38:13:50 | { ..., ... } [Prop1] : Object | J.cs:18:14:18:15 | access to local variable r2 [Prop1] : Object |
245-
| J.cs:13:38:13:50 | { ..., ... } [Prop1] : Object | J.cs:22:14:22:15 | access to local variable r3 [Prop1] : Object |
246-
| J.cs:13:48:13:48 | access to local variable o : Object | J.cs:13:38:13:50 | { ..., ... } [Prop1] : Object |
243+
| J.cs:13:18:13:36 | object creation of type Record [Prop1] : Object | J.cs:14:14:14:15 | access to local variable r1 [Prop1] : Object |
244+
| J.cs:13:18:13:36 | object creation of type Record [Prop1] : Object | J.cs:18:14:18:15 | access to local variable r2 [Prop1] : Object |
245+
| J.cs:13:18:13:36 | object creation of type Record [Prop1] : Object | J.cs:22:14:22:15 | access to local variable r3 [Prop1] : Object |
246+
| J.cs:13:29:13:29 | access to local variable o : Object | J.cs:13:18:13:36 | object creation of type Record [Prop1] : Object |
247247
| J.cs:14:14:14:15 | access to local variable r1 [Prop1] : Object | J.cs:14:14:14:21 | access to property Prop1 |
248248
| J.cs:18:14:18:15 | access to local variable r2 [Prop1] : Object | J.cs:18:14:18:21 | access to property Prop1 |
249249
| J.cs:21:18:21:38 | ... with { ... } [Prop2] : Object | J.cs:23:14:23:15 | access to local variable r3 [Prop2] : Object |
@@ -526,8 +526,8 @@ nodes
526526
| I.cs:40:14:40:14 | access to parameter i [Field1] : Object | semmle.label | access to parameter i [Field1] : Object |
527527
| I.cs:40:14:40:21 | access to field Field1 | semmle.label | access to field Field1 |
528528
| J.cs:12:17:12:28 | object creation of type Object : Object | semmle.label | object creation of type Object : Object |
529-
| J.cs:13:38:13:50 | { ..., ... } [Prop1] : Object | semmle.label | { ..., ... } [Prop1] : Object |
530-
| J.cs:13:48:13:48 | access to local variable o : Object | semmle.label | access to local variable o : Object |
529+
| J.cs:13:18:13:36 | object creation of type Record [Prop1] : Object | semmle.label | object creation of type Record [Prop1] : Object |
530+
| J.cs:13:29:13:29 | access to local variable o : Object | semmle.label | access to local variable o : Object |
531531
| J.cs:14:14:14:15 | access to local variable r1 [Prop1] : Object | semmle.label | access to local variable r1 [Prop1] : Object |
532532
| J.cs:14:14:14:21 | access to property Prop1 | semmle.label | access to property Prop1 |
533533
| J.cs:18:14:18:15 | access to local variable r2 [Prop1] : Object | semmle.label | access to local variable r2 [Prop1] : Object |

csharp/ql/test/library-tests/dataflow/fields/J.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ public class J
1010
private void M1()
1111
{
1212
var o = new object();
13-
var r1 = new Record(o, null) { Prop1 = o }; // todo: ctor should be enough
13+
var r1 = new Record(o, null);
1414
Sink(r1.Prop1); // flow
1515
Sink(r1.Prop2); // no flow
1616

0 commit comments

Comments
 (0)