Skip to content

Commit e9d4e38

Browse files
committed
C#: Convert at least System.Collection.[Generic.]IList flow to CSV format.
1 parent 44c1e3f commit e9d4e38

File tree

19 files changed

+515
-60
lines changed

19 files changed

+515
-60
lines changed

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

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,7 @@ private import internal.FlowSummaryImplSpecific
8686
private module Frameworks {
8787
private import semmle.code.csharp.frameworks.EntityFramework
8888
private import semmle.code.csharp.frameworks.JsonNET
89+
private import semmle.code.csharp.frameworks.microsoft.VisualBasic
8990
private import semmle.code.csharp.frameworks.ServiceStack
9091
private import semmle.code.csharp.frameworks.Sql
9192
private import semmle.code.csharp.frameworks.System
@@ -96,6 +97,7 @@ private module Frameworks {
9697
private import semmle.code.csharp.frameworks.system.collections.ObjectModel
9798
private import semmle.code.csharp.frameworks.system.collections.Specialized
9899
private import semmle.code.csharp.frameworks.system.ComponentModel
100+
private import semmle.code.csharp.frameworks.system.componentmodel.Design
99101
private import semmle.code.csharp.frameworks.system.Data
100102
private import semmle.code.csharp.frameworks.system.data.Common
101103
private import semmle.code.csharp.frameworks.system.Diagnostics
@@ -106,11 +108,15 @@ private module Frameworks {
106108
private import semmle.code.csharp.frameworks.system.IO
107109
private import semmle.code.csharp.frameworks.system.io.Compression
108110
private import semmle.code.csharp.frameworks.system.runtime.CompilerServices
111+
private import semmle.code.csharp.frameworks.system.security.cryptography.X509Certificates
109112
private import semmle.code.csharp.frameworks.system.Text
113+
private import semmle.code.csharp.frameworks.system.text.RegularExpressions
110114
private import semmle.code.csharp.frameworks.system.threading.Tasks
111115
private import semmle.code.csharp.frameworks.system.Web
112116
private import semmle.code.csharp.frameworks.system.web.ui.WebControls
113117
private import semmle.code.csharp.frameworks.system.Xml
118+
private import semmle.code.csharp.frameworks.system.xml.Schema
119+
private import semmle.code.csharp.frameworks.system.xml.Serialization
114120
private import semmle.code.csharp.security.dataflow.flowsinks.Html
115121
private import semmle.code.csharp.security.dataflow.flowsources.Local
116122
private import semmle.code.csharp.security.dataflow.XSSSinks

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

Lines changed: 0 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -624,56 +624,6 @@ class ICollectionFlow extends LibraryTypeDataFlow, RefType {
624624
}
625625
}
626626

627-
/** Data flow for `System.Collections.[Generic.]IList` (and sub types). */
628-
class IListFlow extends LibraryTypeDataFlow, RefType {
629-
IListFlow() {
630-
exists(Interface i | i = this.getABaseType*().getUnboundDeclaration() |
631-
i instanceof SystemCollectionsIListInterface
632-
or
633-
i instanceof SystemCollectionsGenericIListInterface
634-
)
635-
}
636-
637-
override predicate callableFlow(
638-
CallableFlowSource source, AccessPath sourceAp, CallableFlowSink sink, AccessPath sinkAp,
639-
SourceDeclarationCallable c, boolean preservesValue
640-
) {
641-
preservesValue = true and
642-
(
643-
exists(string name, int arity |
644-
name = c.getName() and
645-
arity = c.getNumberOfParameters() and
646-
c = this.getAMethod()
647-
|
648-
name = "Insert" and
649-
arity = 2 and
650-
source = TCallableFlowSourceArg(1) and
651-
sourceAp = AccessPath::empty() and
652-
sink instanceof CallableFlowSinkQualifier and
653-
sinkAp = AccessPath::element()
654-
or
655-
name.regexpMatch("FixedSize|GetRange") and
656-
source = TCallableFlowSourceArg(0) and
657-
sourceAp = AccessPath::element() and
658-
sink = TCallableFlowSinkReturn() and
659-
sinkAp = AccessPath::element()
660-
)
661-
or
662-
c = this.getAnIndexer().getSetter() and
663-
source = TCallableFlowSourceArg(1) and
664-
sourceAp = AccessPath::empty() and
665-
sink instanceof CallableFlowSinkQualifier and
666-
sinkAp = AccessPath::element()
667-
or
668-
c = this.getAnIndexer().getGetter() and
669-
source instanceof CallableFlowSourceQualifier and
670-
sourceAp = AccessPath::element() and
671-
sink instanceof CallableFlowSinkReturn and
672-
sinkAp = AccessPath::empty()
673-
)
674-
}
675-
}
676-
677627
abstract private class SyntheticTaskField extends SyntheticField {
678628
bindingset[this]
679629
SyntheticTaskField() { any() }

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

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -271,4 +271,26 @@ module JsonNET {
271271
]
272272
}
273273
}
274+
275+
/** Data flow for `Newtonsoft.JSon.Linq.JArray` */
276+
private class NewtonsoftJsonLinqJArrayFlowModelCsv extends SummaryModelCsv {
277+
override predicate row(string row) {
278+
row =
279+
[
280+
"Newtonsoft.Json.Linq;JArray;false;get_Item;(System.Object);;Element of Argument[-1];ReturnValue;value",
281+
"Newtonsoft.Json.Linq;JArray;false;set_Item;(System.Object,Newtonsoft.Json.Linq.JToken);;Argument[1];Element of Argument[-1];value",
282+
]
283+
}
284+
}
285+
286+
/** Data flow for `Newtonsoft.JSon.Linq.JConstructor` */
287+
private class NewtonsoftJsonLinqJConstructorFlowModelCsv extends SummaryModelCsv {
288+
override predicate row(string row) {
289+
row =
290+
[
291+
"Newtonsoft.Json.Linq;JConstructor;false;get_Item;(System.Object);;Element of Argument[-1];ReturnValue;value",
292+
"Newtonsoft.Json.Linq;JConstructor;false;set_Item;(System.Object,Newtonsoft.Json.Linq.JToken);;Argument[1];Element of Argument[-1];value",
293+
]
294+
}
295+
}
274296
}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
/** Provides definitions related to the `Microsoft.VisualBasic` namespace. */
2+
3+
private import semmle.code.csharp.dataflow.ExternalFlow
4+
5+
/** Data flow for `Microsoft.VisualBasic.Collection`. */
6+
private class MicrosoftVisualBasicCollectionFlowModelCsv extends SummaryModelCsv {
7+
override predicate row(string row) {
8+
row =
9+
[
10+
"Microsoft.VisualBasic;Collection;false;GetEnumerator;();;Element of Argument[-1];Property[System.Collections.IEnumerator.Current] of ReturnValue;value",
11+
"Microsoft.VisualBasic;Collection;false;get_Item;(System.Int32);;Element of Argument[-1];ReturnValue;value",
12+
"Microsoft.VisualBasic;Collection;false;get_Item;(System.Object);;Element of Argument[-1];ReturnValue;value",
13+
"Microsoft.VisualBasic;Collection;false;get_Item;(System.String);;Element of Argument[-1];ReturnValue;value",
14+
]
15+
}
16+
}

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

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,19 @@ class SystemCollectionsIListInterface extends SystemCollectionsInterface {
6767
SystemCollectionsIListInterface() { this.hasName("IList") }
6868
}
6969

70+
/** Data flow for `System.Collections.IList`. */
71+
private class SystemCollectionsIListFlowModelCsv extends SummaryModelCsv {
72+
override predicate row(string row) {
73+
row =
74+
[
75+
"System.Collections;IList;true;Add;(System.Object);;Argument[0];Element of Argument[-1];value",
76+
"System.Collections;IList;true;Insert;(System.Int32,System.Object);;Argument[1];Element of Argument[-1];value",
77+
"System.Collections;IList;true;get_Item;(System.Int32);;Element of Argument[-1];ReturnValue;value",
78+
"System.Collections;IList;true;set_Item;(System.Int32,System.Object);;Argument[1];Element of Argument[-1];value",
79+
]
80+
}
81+
}
82+
7083
/** The `System.Collections.IDictionary` interface. */
7184
class SystemCollectionsIDictionaryInterface extends SystemCollectionsInterface {
7285
SystemCollectionsIDictionaryInterface() { this.hasName("IDictionary") }
@@ -125,3 +138,22 @@ private class SystemCollectionsSortedListFlowModelCsv extends SummaryModelCsv {
125138
]
126139
}
127140
}
141+
142+
/** Data flow for `System.Collections.ArrayList`. */
143+
private class SystemCollectionsArrayListFlowModelCsv extends SummaryModelCsv {
144+
override predicate row(string row) {
145+
row =
146+
[
147+
"System.Collections;ArrayList;false;AddRange;(System.Collections.ICollection);;Element of Argument[0];Element of Argument[-1];value",
148+
"System.Collections;ArrayList;false;Clone;();;Element of Argument[0];Element of ReturnValue;value",
149+
"System.Collections;ArrayList;false;FixedSize;(System.Collections.ArrayList);;Element of Argument[0];Element of ReturnValue;value",
150+
"System.Collections;ArrayList;false;FixedSize;(System.Collections.IList);;Element of Argument[0];Element of ReturnValue;value",
151+
"System.Collections;ArrayList;false;GetEnumerator;(System.Int32,System.Int32);;Element of Argument[-1];Property[System.Collections.IEnumerator.Current] of ReturnValue;value",
152+
"System.Collections;ArrayList;false;GetRange;(System.Int32,System.Int32);;Element of Argument[0];Element of ReturnValue;value",
153+
"System.Collections;ArrayList;false;InsertRange;(System.Int32,System.Collections.ICollection);;Element of Argument[1];Element of Argument[-1];value",
154+
"System.Collections;ArrayList;false;Repeat;(System.Object,System.Int32);;Argument[0];Element of ReturnValue;value",
155+
"System.Collections;ArrayList;false;Reverse;();;Element of Argument[0];Element of ReturnValue;value",
156+
"System.Collections;ArrayList;false;Reverse;(System.Int32,System.Int32);;Element of Argument[0];Element of ReturnValue;value",
157+
]
158+
}
159+
}

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

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,3 +30,29 @@ private class SystemComponentModelPropertyDescriptorCollectionFlowModelCsv exten
3030
]
3131
}
3232
}
33+
34+
/** Data flow for `System.ComponentModel.EventDescriptorCollection`. */
35+
private class SystemComponentModelEventDescriptorCollectionFlowModelCsv extends SummaryModelCsv {
36+
override predicate row(string row) {
37+
row =
38+
[
39+
"System.ComponentModel;EventDescriptorCollection;false;Add;(System.ComponentModel.EventDescriptor);;Argument[0];Element of Argument[-1];value",
40+
"System.ComponentModel;EventDescriptorCollection;false;Find;(System.String,System.Boolean);;Element of Argument[-1];ReturnValue;value",
41+
"System.ComponentModel;EventDescriptorCollection;false;GetEnumerator;();;Element of Argument[-1];Property[System.Collections.IEnumerator.Current] of ReturnValue;value",
42+
"System.ComponentModel;EventDescriptorCollection;false;Insert;(System.Int32,System.ComponentModel.EventDescriptor);;Argument[1];Element of Argument[-1];value",
43+
"System.ComponentModel;EventDescriptorCollection;false;get_Item;(System.Int32);;Element of Argument[-1];ReturnValue;value",
44+
"System.ComponentModel;EventDescriptorCollection;false;get_Item;(System.String);;Element of Argument[-1];ReturnValue;value",
45+
]
46+
}
47+
}
48+
49+
/** Data flow for `System.ComponentModel.ListSortDescriptionCollection`. */
50+
private class SystemComponentModelListSortDescriptionCollectionFlowModelCsv extends SummaryModelCsv {
51+
override predicate row(string row) {
52+
row =
53+
[
54+
"System.ComponentModel;ListSortDescriptionCollection;false;get_Item;(System.Int32);;Element of Argument[-1];ReturnValue;value",
55+
"System.ComponentModel;ListSortDescriptionCollection;false;set_Item;(System.Int32,System.ComponentModel.ListSortDescription);;Argument[1];Element of Argument[-1];value",
56+
]
57+
}
58+
}

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

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,3 +97,48 @@ private class SystemDataTypedTableBaseExtensionsFlowModelCsv extends SummaryMode
9797
]
9898
}
9999
}
100+
101+
/** Data flow for `System.Data.DataView`. */
102+
private class SystemDataDataViewFlowModelCsv extends SummaryModelCsv {
103+
override predicate row(string row) {
104+
row =
105+
[
106+
"System.Data;DataView;false;Find;(System.Object);;Element of Argument[-1];ReturnValue;value",
107+
"System.Data;DataView;false;Find;(System.Object[]);;Element of Argument[-1];ReturnValue;value",
108+
"System.Data;DataView;false;get_Item;(System.Int32);;Element of Argument[-1];ReturnValue;value",
109+
]
110+
}
111+
}
112+
113+
/** Data flow for `System.Data.IColumnMappingCollection`. */
114+
private class SystemDataIColumnMappingCollectionFlowModelCsv extends SummaryModelCsv {
115+
override predicate row(string row) {
116+
row =
117+
[
118+
"System.Data;IColumnMappingCollection;true;get_Item;(System.String);;Element of Argument[-1];ReturnValue;value",
119+
"System.Data;IColumnMappingCollection;true;set_Item;(System.String,System.Object);;Argument[1];Element of Argument[-1];value",
120+
]
121+
}
122+
}
123+
124+
/** Data flow for `System.Data.IDataParameterCollection`. */
125+
private class SystemDataIDataParameterCollectionFlowModelCsv extends SummaryModelCsv {
126+
override predicate row(string row) {
127+
row =
128+
[
129+
"System.Data;IDataParameterCollection;true;get_Item;(System.String);;Element of Argument[-1];ReturnValue;value",
130+
"System.Data;IDataParameterCollection;true;set_Item;(System.String,System.Object);;Argument[1];Element of Argument[-1];value",
131+
]
132+
}
133+
}
134+
135+
/** Data flow for `System.Data.ITableMappingCollection`. */
136+
private class SystemDataITableMappingCollectionFlowModelCsv extends SummaryModelCsv {
137+
override predicate row(string row) {
138+
row =
139+
[
140+
"System.Data;ITableMappingCollection;true;get_Item;(System.String);;Element of Argument[-1];ReturnValue;value",
141+
"System.Data;ITableMappingCollection;true;set_Item;(System.String,System.Object);;Argument[1];Element of Argument[-1];value",
142+
]
143+
}
144+
}

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

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,3 +94,20 @@ private class SystemDiagnosticsActivityTagsCollectionFlowModelCsv extends Summar
9494
]
9595
}
9696
}
97+
98+
/** Data flow for `System.Diagnostics.TraceListenerCollection`. */
99+
private class SystemDiagnosticsTraceListenerCollectionFlowModelCsv extends SummaryModelCsv {
100+
override predicate row(string row) {
101+
row =
102+
[
103+
"System.Diagnostics;TraceListenerCollection;false;Add;(System.Diagnostics.TraceListener);;Argument[0];Element of Argument[-1];value",
104+
"System.Diagnostics;TraceListenerCollection;false;AddRange;(System.Diagnostics.TraceListenerCollection);;Element of Argument[0];Element of Argument[-1];value",
105+
"System.Diagnostics;TraceListenerCollection;false;AddRange;(System.Diagnostics.TraceListener[]);;Element of Argument[0];Element of Argument[-1];value",
106+
"System.Diagnostics;TraceListenerCollection;false;CopyTo;(System.Diagnostics.TraceListener[],System.Int32);;Element of Argument[-1];Element of Argument[0];value",
107+
"System.Diagnostics;TraceListenerCollection;false;Insert;(System.Int32,System.Diagnostics.TraceListener);;Argument[1];Element of Argument[-1];value",
108+
"System.Diagnostics;TraceListenerCollection;false;get_Item;(System.Int32);;Element of Argument[-1];ReturnValue;value",
109+
"System.Diagnostics;TraceListenerCollection;false;get_Item;(System.String);;Element of Argument[-1];ReturnValue;value",
110+
"System.Diagnostics;TraceListenerCollection;false;set_Item;(System.Int32,System.Diagnostics.TraceListener);;Argument[1];Element of Argument[-1];value",
111+
]
112+
}
113+
}

0 commit comments

Comments
 (0)