Skip to content

Commit f43feac

Browse files
committed
C#: Add models as data models for Clear.
1 parent 80f8928 commit f43feac

File tree

16 files changed

+139
-19
lines changed

16 files changed

+139
-19
lines changed

csharp/ql/lib/semmle/code/csharp/dataflow/ExternalFlow.qll

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,7 @@ private module Frameworks {
110110
private import semmle.code.csharp.frameworks.system.collections.Specialized
111111
private import semmle.code.csharp.frameworks.system.ComponentModel
112112
private import semmle.code.csharp.frameworks.system.componentmodel.Design
113+
private import semmle.code.csharp.frameworks.system.Configuration
113114
private import semmle.code.csharp.frameworks.system.Data
114115
private import semmle.code.csharp.frameworks.system.data.Common
115116
private import semmle.code.csharp.frameworks.system.Diagnostics

csharp/ql/lib/semmle/code/csharp/frameworks/System.qll

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,8 @@ private class SystemArrayFlowModelCsv extends SummaryModelCsv {
7171
row =
7272
[
7373
"System;Array;false;AsReadOnly<>;(T[]);;Argument[0].Element;ReturnValue.Element;value;manual",
74+
"System;Array;false;Clear;(System.Array,System.Int32,System.Int32);;Argument[0].WithoutElement;Argument[0];value;manual",
75+
"System;Array;false;Clear;(System.Array);;Argument[0].WithoutElement;Argument[0];value;manual",
7476
"System;Array;false;Clone;();;Argument[0].Element;ReturnValue.Element;value;manual",
7577
"System;Array;false;CopyTo;(System.Array,System.Int64);;Argument[this].Element;Argument[0].Element;value;manual",
7678
"System;Array;false;Find<>;(T[],System.Predicate<T>);;Argument[0].Element;Argument[1].Parameter[0];value;manual",

csharp/ql/lib/semmle/code/csharp/frameworks/microsoft/VisualBasic.qll

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ private class MicrosoftVisualBasicCollectionFlowModelCsv extends SummaryModelCsv
77
override predicate row(string row) {
88
row =
99
[
10+
"Microsoft.VisualBasic;Collection;false;Clear;();;Argument[this].WithoutElement;Argument[this];value;manual",
1011
"Microsoft.VisualBasic;Collection;false;GetEnumerator;();;Argument[this].Element;ReturnValue.Property[System.Collections.IEnumerator.Current];value;manual",
1112
"Microsoft.VisualBasic;Collection;false;get_Item;(System.Int32);;Argument[this].Element;ReturnValue;value;manual",
1213
"Microsoft.VisualBasic;Collection;false;get_Item;(System.Object);;Argument[this].Element;ReturnValue;value;manual",

csharp/ql/lib/semmle/code/csharp/frameworks/system/CodeDom.qll

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
import csharp
44
private import semmle.code.csharp.frameworks.System
5+
private import semmle.code.csharp.dataflow.ExternalFlow
56

67
/** The `System.CodeDome` namespace. */
78
class SystemCodeDomNamespace extends Namespace {
@@ -10,3 +11,11 @@ class SystemCodeDomNamespace extends Namespace {
1011
this.hasName("CodeDom")
1112
}
1213
}
14+
15+
/** Data flow for `System.CodeDom.CodeNamespaceImportCollection`. */
16+
private class SystemCodeDomCodeNamespaceImportCollectionFlowModelCsv extends SummaryModelCsv {
17+
override predicate row(string row) {
18+
row =
19+
"System.CodeDom;CodeNamespaceImportCollection;false;Clear;();;Argument[this].WithoutElement;Argument[this];value;manual"
20+
}
21+
}

csharp/ql/lib/semmle/code/csharp/frameworks/system/Collections.qll

Lines changed: 4 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -46,20 +46,6 @@ private class SystemCollectionIEnumerableFlowModelCsv extends SummaryModelCsv {
4646
}
4747
}
4848

49-
/** Clear content for Clear methods in all subtypes of `System.Collections.IEnumerable`. */
50-
private class SystemCollectionsIEnumerableClearFlow extends SummarizedCallable {
51-
SystemCollectionsIEnumerableClearFlow() {
52-
this.getDeclaringType().(RefType).getABaseType*() instanceof
53-
SystemCollectionsIEnumerableInterface and
54-
this.hasName("Clear")
55-
}
56-
57-
override predicate clearsContent(ParameterPosition pos, DataFlow::ContentSet content) {
58-
(if this.(Modifiable).isStatic() then pos.getPosition() = 0 else pos.isThisParameter()) and
59-
content instanceof DataFlow::ElementContent
60-
}
61-
}
62-
6349
/** The `System.Collections.IEnumerator` interface. */
6450
class SystemCollectionsIEnumeratorInterface extends SystemCollectionsInterface {
6551
SystemCollectionsIEnumeratorInterface() { this.hasName("IEnumerator") }
@@ -96,6 +82,7 @@ private class SystemCollectionsIListFlowModelCsv extends SummaryModelCsv {
9682
row =
9783
[
9884
"System.Collections;IList;true;Add;(System.Object);;Argument[0];Argument[this].Element;value;manual",
85+
"System.Collections;IList;true;Clear;();;Argument[this].WithoutElement;Argument[this];value;manual",
9986
"System.Collections;IList;true;Insert;(System.Int32,System.Object);;Argument[1];Argument[this].Element;value;manual",
10087
"System.Collections;IList;true;get_Item;(System.Int32);;Argument[this].Element;ReturnValue;value;manual",
10188
"System.Collections;IList;true;set_Item;(System.Int32,System.Object);;Argument[1];Argument[this].Element;value;manual",
@@ -115,6 +102,7 @@ private class SystemCollectionsIDictionaryFlowModelCsv extends SummaryModelCsv {
115102
[
116103
"System.Collections;IDictionary;true;Add;(System.Object,System.Object);;Argument[0];Argument[this].Element.Property[System.Collections.Generic.KeyValuePair<,>.Key];value;manual",
117104
"System.Collections;IDictionary;true;Add;(System.Object,System.Object);;Argument[1];Argument[this].Element.Property[System.Collections.Generic.KeyValuePair<,>.Value];value;manual",
105+
"System.Collections;IDictionary;true;Clear;();;Argument[this].WithoutElement;Argument[this];value;manual",
118106
"System.Collections;IDictionary;true;get_Item;(System.Object);;Argument[this].Element.Property[System.Collections.Generic.KeyValuePair<,>.Value];ReturnValue;value;manual",
119107
"System.Collections;IDictionary;true;get_Keys;();;Argument[this].Element.Property[System.Collections.Generic.KeyValuePair<,>.Key];ReturnValue.Element;value;manual",
120108
"System.Collections;IDictionary;true;get_Values;();;Argument[this].Element.Property[System.Collections.Generic.KeyValuePair<,>.Value];ReturnValue.Element;value;manual",
@@ -194,6 +182,7 @@ private class SystemCollectionsQueueFlowModelCsv extends SummaryModelCsv {
194182
override predicate row(string row) {
195183
row =
196184
[
185+
"System.Collections;Queue;true;Clear;();;Argument[this].WithoutElement;Argument[this];value;manual",
197186
"System.Collections;Queue;false;Clone;();;Argument[0].Element;ReturnValue.Element;value;manual",
198187
"System.Collections;Queue;false;Peek;();;Argument[this].Element;ReturnValue;value;manual",
199188
]
@@ -205,6 +194,7 @@ private class SystemCollectionsStackFlowModelCsv extends SummaryModelCsv {
205194
override predicate row(string row) {
206195
row =
207196
[
197+
"System.Collections;Stack;false;Clear;();;Argument[this].WithoutElement;Argument[this];value;manual",
208198
"System.Collections;Stack;false;Clone;();;Argument[0].Element;ReturnValue.Element;value;manual",
209199
"System.Collections;Stack;false;Peek;();;Argument[this].Element;ReturnValue;value;manual",
210200
"System.Collections;Stack;false;Pop;();;Argument[this].Element;ReturnValue;value;manual",

csharp/ql/lib/semmle/code/csharp/frameworks/system/ComponentModel.qll

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ private class SystemComponentModelPropertyDescriptorCollectionFlowModelCsv exten
1212
"System.ComponentModel;PropertyDescriptorCollection;false;Add;(System.ComponentModel.PropertyDescriptor);;Argument[0].Property[System.Collections.Generic.KeyValuePair<,>.Value];Argument[this].Element.Property[System.Collections.Generic.KeyValuePair<,>.Value];value;manual",
1313
"System.ComponentModel;PropertyDescriptorCollection;false;Add;(System.Object);;Argument[0].Property[System.Collections.Generic.KeyValuePair<,>.Key];Argument[this].Element.Property[System.Collections.Generic.KeyValuePair<,>.Key];value;manual",
1414
"System.ComponentModel;PropertyDescriptorCollection;false;Add;(System.Object);;Argument[0].Property[System.Collections.Generic.KeyValuePair<,>.Value];Argument[this].Element.Property[System.Collections.Generic.KeyValuePair<,>.Value];value;manual",
15+
"System.ComponentModel;PropertyDescriptorCollection;false;Clear;();;Argument[this].WithoutElement;Argument[this];value;manual",
1516
"System.ComponentModel;PropertyDescriptorCollection;false;Find;(System.String,System.Boolean);;Argument[this].Element;ReturnValue;value;manual",
1617
"System.ComponentModel;PropertyDescriptorCollection;false;GetEnumerator;();;Argument[this].Element;ReturnValue.Property[System.Collections.IEnumerator.Current];value;manual",
1718
"System.ComponentModel;PropertyDescriptorCollection;false;Insert;(System.Int32,System.ComponentModel.PropertyDescriptor);;Argument[1];Argument[this].Element;value;manual",
@@ -37,6 +38,7 @@ private class SystemComponentModelEventDescriptorCollectionFlowModelCsv extends
3738
row =
3839
[
3940
"System.ComponentModel;EventDescriptorCollection;false;Add;(System.ComponentModel.EventDescriptor);;Argument[0];Argument[this].Element;value;manual",
41+
"System.ComponentModel;EventDescriptorCollection;false;Clear;();;Argument[this].WithoutElement;Argument[this];value;manual",
4042
"System.ComponentModel;EventDescriptorCollection;false;Find;(System.String,System.Boolean);;Argument[this].Element;ReturnValue;value;manual",
4143
"System.ComponentModel;EventDescriptorCollection;false;GetEnumerator;();;Argument[this].Element;ReturnValue.Property[System.Collections.IEnumerator.Current];value;manual",
4244
"System.ComponentModel;EventDescriptorCollection;false;Insert;(System.Int32,System.ComponentModel.EventDescriptor);;Argument[1];Argument[this].Element;value;manual",
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
/** Provides definitions related to the namespace `System.Configuration`. */
2+
3+
import csharp
4+
private import semmle.code.csharp.dataflow.ExternalFlow
5+
6+
/** Data flow for some collection classes in `System.Configuration.*`. */
7+
private class SystemClearFlowModelCsv extends SummaryModelCsv {
8+
override predicate row(string row) {
9+
row =
10+
[
11+
"System.Configuration;CommaDelimitedStringCollection;false;Clear;();;Argument[this].WithoutElement;Argument[this];value;manual",
12+
"System.Configuration;ConfigurationLockCollection;false;Clear;();;Argument[this].WithoutElement;Argument[this];value;manual",
13+
"System.Configuration;ConfigurationPropertyCollection;false;Clear;();;Argument[this].WithoutElement;Argument[this];value;manual",
14+
"System.Configuration;ConfigurationSectionCollection;false;Clear;();;Argument[this].WithoutElement;Argument[this];value;manual",
15+
"System.Configuration;ConfigurationSectionGroupCollection;false;Clear;();;Argument[this].WithoutElement;Argument[this];value;manual",
16+
"System.Configuration;ConnectionStringSettingsCollection;false;Clear;();;Argument[this].WithoutElement;Argument[this];value;manual",
17+
"System.Configuration;KeyValueConfigurationCollection;false;Clear;();;Argument[this].WithoutElement;Argument[this];value;manual",
18+
"System.Configuration;NameValueConfigurationCollection;false;Clear;();;Argument[this].WithoutElement;Argument[this];value;manual",
19+
"System.Configuration;ProviderSettingsCollection;false;Clear;();;Argument[this].WithoutElement;Argument[this];value;manual",
20+
"System.Configuration;SettingElementCollection;false;Clear;();;Argument[this].WithoutElement;Argument[this];value;manual",
21+
"System.Configuration;SettingsPropertyCollection;false;Clear;();;Argument[this].WithoutElement;Argument[this];value;manual",
22+
"System.Configuration;SettingsPropertyValueCollection;false;Clear;();;Argument[this].WithoutElement;Argument[this];value;manual",
23+
"System.Configuration.Provider;ProviderCollection;false;Clear;();;Argument[this].WithoutElement;Argument[this];value;manual",
24+
]
25+
}
26+
}

csharp/ql/lib/semmle/code/csharp/frameworks/system/Data.qll

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,7 @@ private class SystemDataConstraintCollectionFlowModelCsv extends SummaryModelCsv
150150
[
151151
"System.Data;ConstraintCollection;false;Add;(System.Data.Constraint);;Argument[0];Argument[this].Element;value;manual",
152152
"System.Data;ConstraintCollection;false;AddRange;(System.Data.Constraint[]);;Argument[0].Element;Argument[this].Element;value;manual",
153+
"System.Data;ConstraintCollection;false;Clear;();;Argument[this].WithoutElement;Argument[this];value;manual",
153154
"System.Data;ConstraintCollection;false;CopyTo;(System.Data.Constraint[],System.Int32);;Argument[this].Element;Argument[0].Element;value;manual",
154155
]
155156
}
@@ -163,6 +164,7 @@ private class SystemDataDataColumnCollectionFlowModelCsv extends SummaryModelCsv
163164
"System.Data;DataColumnCollection;false;Add;(System.Data.DataColumn);;Argument[0];Argument[this].Element;value;manual",
164165
"System.Data;DataColumnCollection;false;Add;(System.String);;Argument[0];Argument[this].Element;value;manual",
165166
"System.Data;DataColumnCollection;false;AddRange;(System.Data.DataColumn[]);;Argument[0].Element;Argument[this].Element;value;manual",
167+
"System.Data;DataColumnCollection;false;Clear;();;Argument[this].WithoutElement;Argument[this];value;manual",
166168
"System.Data;DataColumnCollection;false;CopyTo;(System.Data.DataColumn[],System.Int32);;Argument[this].Element;Argument[0].Element;value;manual",
167169
]
168170
}
@@ -174,6 +176,7 @@ private class SystemDataDataRelationCollectionFlowModelCsv extends SummaryModelC
174176
row =
175177
[
176178
"System.Data;DataRelationCollection;false;Add;(System.Data.DataRelation);;Argument[0];Argument[this].Element;value;manual",
179+
"System.Data;DataRelationCollection;true;Clear;();;Argument[this].WithoutElement;Argument[this];value;manual",
177180
"System.Data;DataRelationCollection;false;CopyTo;(System.Data.DataRelation[],System.Int32);;Argument[this].Element;Argument[0].Element;value;manual",
178181
"System.Data;DataRelationCollection;true;AddRange;(System.Data.DataRelation[]);;Argument[0].Element;Argument[this].Element;value;manual",
179182
]
@@ -187,6 +190,7 @@ private class SystemDataDataRawCollectionFlowModelCsv extends SummaryModelCsv {
187190
[
188191
"System.Data;DataRowCollection;false;Add;(System.Data.DataRow);;Argument[0];Argument[this].Element;value;manual",
189192
"System.Data;DataRowCollection;false;Add;(System.Object[]);;Argument[0];Argument[this].Element;value;manual",
193+
"System.Data;DataRowCollection;false;Clear;();;Argument[this].WithoutElement;Argument[this];value;manual",
190194
"System.Data;DataRowCollection;false;CopyTo;(System.Data.DataRow[],System.Int32);;Argument[this].Element;Argument[0].Element;value;manual",
191195
"System.Data;DataRowCollection;false;Find;(System.Object);;Argument[this].Element;ReturnValue;value;manual",
192196
"System.Data;DataRowCollection;false;Find;(System.Object[]);;Argument[this].Element;ReturnValue;value;manual",
@@ -202,6 +206,7 @@ private class SystemDataDataTableCollectionFlowModelCsv extends SummaryModelCsv
202206
"System.Data;DataTableCollection;false;Add;(System.Data.DataTable);;Argument[0];Argument[this].Element;value;manual",
203207
"System.Data;DataTableCollection;false;Add;(System.String);;Argument[0];Argument[this].Element;value;manual",
204208
"System.Data;DataTableCollection;false;AddRange;(System.Data.DataTable[]);;Argument[0].Element;Argument[this].Element;value;manual",
209+
"System.Data;DataTableCollection;false;Clear;();;Argument[this].WithoutElement;Argument[this];value;manual",
205210
"System.Data;DataTableCollection;false;CopyTo;(System.Data.DataTable[],System.Int32);;Argument[this].Element;Argument[0].Element;value;manual",
206211
]
207212
}

csharp/ql/lib/semmle/code/csharp/frameworks/system/Security.qll

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
/** Provides classes related to the namespace `System.Security`. */
22

33
import csharp
4+
private import semmle.code.csharp.dataflow.ExternalFlow
45
private import semmle.code.csharp.frameworks.System
56

67
/** The `System.Security` namespace. */
@@ -15,3 +16,15 @@ class SystemSecurityNamespace extends Namespace {
1516
class SystemSecurityClass extends Class {
1617
SystemSecurityClass() { this.getNamespace() instanceof SystemSecurityNamespace }
1718
}
19+
20+
/** Data flow for some collection like classes in `System.Security.*`. */
21+
private class SystemSecurityPolicyApplicationTrustCollectionFlowModelCsv extends SummaryModelCsv {
22+
override predicate row(string row) {
23+
row =
24+
[
25+
"System.Security.Permissions;KeyContainerPermissionAccessEntryCollection;false;Clear;();;Argument[this].WithoutElement;Argument[this];value;manual",
26+
"System.Security.Policy;ApplicationTrustCollection;false;Clear;();;Argument[this].WithoutElement;Argument[this];value;manual",
27+
"System.Security.Policy;Evidence;false;Clear;();;Argument[this].WithoutElement;Argument[this];value;manual",
28+
]
29+
}
30+
}

csharp/ql/lib/semmle/code/csharp/frameworks/system/collections/Concurrent.qll

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,25 @@ private class SystemCollectionsConcurrentIProducerConsumerCollectionFlowModelCsv
4444
private class SystemCollectionsConcurrentConcurrentBagFlowModelCsv extends SummaryModelCsv {
4545
override predicate row(string row) {
4646
row =
47-
"System.Collections.Concurrent;ConcurrentBag<>;false;Add;(T);;Argument[0];Argument[this].Element;value;manual"
47+
[
48+
"System.Collections.Concurrent;ConcurrentBag<>;false;Add;(T);;Argument[0];Argument[this].Element;value;manual",
49+
"System.Collections.Concurrent;ConcurrentBag<>;false;Clear;();;Argument[this].WithoutElement;Argument[this];value;manual",
50+
]
51+
}
52+
}
53+
54+
/** Data flow for `System.Collections.Concurrent.ConcurrentQueue<>`. */
55+
private class SystemCollectionsConcurrentConcurrentQueueFlowModelCsv extends SummaryModelCsv {
56+
override predicate row(string row) {
57+
row =
58+
"System.Collections.Concurrent;ConcurrentQueue<>;false;Clear;();;Argument[this].WithoutElement;Argument[this];value;manual"
59+
}
60+
}
61+
62+
/** Data flow for `System.Collections.Concurrent.ConcurrentStack<>`. */
63+
private class SystemCollectionsConcurrentConcurrentStackFlowModelCsv extends SummaryModelCsv {
64+
override predicate row(string row) {
65+
row =
66+
"System.Collections.Concurrent;ConcurrentStack<>;false;Clear;();;Argument[this].WithoutElement;Argument[this];value;manual"
4867
}
4968
}

0 commit comments

Comments
 (0)