Skip to content

Commit aedfc42

Browse files
committed
C#: Convert at least the flow summaries for System.Collections[.Generic].IDictionary and subclasses.
1 parent b78ec4c commit aedfc42

File tree

14 files changed

+360
-87
lines changed

14 files changed

+360
-87
lines changed

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

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,16 @@ private module Frameworks {
104104
private import semmle.code.csharp.frameworks.system.runtime.CompilerServices
105105
private import semmle.code.csharp.frameworks.system.Linq
106106
private import semmle.code.csharp.frameworks.system.Data
107+
private import semmle.code.csharp.frameworks.system.collections.Specialized
108+
private import semmle.code.csharp.frameworks.system.collections.Immutable
109+
private import semmle.code.csharp.frameworks.system.collections.Concurrent
110+
private import semmle.code.csharp.frameworks.system.collections.ObjectModel
111+
private import semmle.code.csharp.frameworks.system.ComponentModel
112+
private import semmle.code.csharp.frameworks.system.data.Common
113+
private import semmle.code.csharp.frameworks.system.Diagnostics
114+
private import semmle.code.csharp.frameworks.system.Dynamic
115+
private import semmle.code.csharp.frameworks.system.net.Http
116+
private import semmle.code.csharp.frameworks.system.Collections
107117
}
108118

109119
/**

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

Lines changed: 0 additions & 86 deletions
Original file line numberDiff line numberDiff line change
@@ -674,92 +674,6 @@ class IListFlow extends LibraryTypeDataFlow, RefType {
674674
}
675675
}
676676

677-
/** Data flow for `System.Collections.[Generic.]IDictionary` (and sub types). */
678-
class IDictionaryFlow extends LibraryTypeDataFlow, RefType {
679-
IDictionaryFlow() {
680-
exists(Interface i | i = this.getABaseType*().getUnboundDeclaration() |
681-
i instanceof SystemCollectionsIDictionaryInterface
682-
or
683-
i instanceof SystemCollectionsGenericIDictionaryInterface
684-
)
685-
}
686-
687-
override predicate callableFlow(
688-
CallableFlowSource source, AccessPath sourceAp, CallableFlowSink sink, AccessPath sinkAp,
689-
SourceDeclarationCallable c, boolean preservesValue
690-
) {
691-
preservesValue = true and
692-
exists(SystemCollectionsGenericKeyValuePairStruct kvp |
693-
exists(int i |
694-
c = this.getAConstructor() and
695-
source = TCallableFlowSourceArg(i) and
696-
sourceAp = sinkAp and
697-
c.getParameter(i).getType().(ValueOrRefType).getABaseType*() instanceof
698-
SystemCollectionsIEnumerableInterface and
699-
sink instanceof CallableFlowSinkReturn
700-
|
701-
sinkAp = AccessPath::properties(kvp.getKeyProperty())
702-
or
703-
sinkAp = AccessPath::properties(kvp.getValueProperty())
704-
)
705-
or
706-
c = this.getProperty("Keys").getGetter() and
707-
source instanceof CallableFlowSourceQualifier and
708-
sourceAp = AccessPath::properties(kvp.getKeyProperty()) and
709-
sink instanceof CallableFlowSinkReturn and
710-
sinkAp = AccessPath::element()
711-
or
712-
(
713-
c = this.getProperty("Values").getGetter()
714-
or
715-
c = this.getAMethod("GetValueList")
716-
) and
717-
source instanceof CallableFlowSourceQualifier and
718-
sourceAp = AccessPath::properties(kvp.getValueProperty()) and
719-
sink instanceof CallableFlowSinkReturn and
720-
sinkAp = AccessPath::element()
721-
or
722-
(
723-
c = this.getAMethod("Add") and
724-
c.getNumberOfParameters() = 2
725-
or
726-
c = this.getAnIndexer().getSetter()
727-
) and
728-
(
729-
source = TCallableFlowSourceArg(0) and
730-
sourceAp = AccessPath::empty() and
731-
sink instanceof CallableFlowSinkQualifier and
732-
sinkAp = AccessPath::properties(kvp.getKeyProperty())
733-
or
734-
source = TCallableFlowSourceArg(1) and
735-
sourceAp = AccessPath::empty() and
736-
sink instanceof CallableFlowSinkQualifier and
737-
sinkAp = AccessPath::properties(kvp.getValueProperty())
738-
)
739-
or
740-
exists(Property p |
741-
c = this.getAMethod("Add") and
742-
c.getNumberOfParameters() = 1 and
743-
source = TCallableFlowSourceArg(0) and
744-
sourceAp = AccessPath::property(p) and
745-
sink instanceof CallableFlowSinkQualifier and
746-
sinkAp = AccessPath::properties(p) and
747-
p = kvp.getAProperty()
748-
)
749-
or
750-
(
751-
c = this.getAnIndexer().getGetter()
752-
or
753-
c = this.getAMethod("GetByIndex")
754-
) and
755-
source instanceof CallableFlowSourceQualifier and
756-
sourceAp = AccessPath::properties(kvp.getValueProperty()) and
757-
sink instanceof CallableFlowSinkReturn and
758-
sinkAp = AccessPath::empty()
759-
)
760-
}
761-
}
762-
763677
abstract private class SyntheticTaskField extends SyntheticField {
764678
bindingset[this]
765679
SyntheticTaskField() { any() }

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

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -253,8 +253,21 @@ module JsonNET {
253253
override predicate row(string row) {
254254
row =
255255
[
256+
"Newtonsoft.Json.Linq;JObject;false;Add;(System.Collections.Generic.KeyValuePair<System.String,Newtonsoft.Json.Linq.JToken>);;Property[System.Collections.Generic.KeyValuePair<,>.Key] of Argument[0];Property[System.Collections.Generic.KeyValuePair<,>.Key] of Element of Argument[-1];value",
257+
"Newtonsoft.Json.Linq;JObject;false;Add;(System.Collections.Generic.KeyValuePair<System.String,Newtonsoft.Json.Linq.JToken>);;Property[System.Collections.Generic.KeyValuePair<,>.Value] of Argument[0];Property[System.Collections.Generic.KeyValuePair<,>.Value] of Element of Argument[-1];value",
258+
"Newtonsoft.Json.Linq;JObject;false;JObject;(Newtonsoft.Json.Linq.JObject);;Property[System.Collections.Generic.KeyValuePair<,>.Key] of Element of Argument[0];Property[System.Collections.Generic.KeyValuePair<,>.Key] of Element of ReturnValue;value",
259+
"Newtonsoft.Json.Linq;JObject;false;JObject;(Newtonsoft.Json.Linq.JObject);;Property[System.Collections.Generic.KeyValuePair<,>.Value] of Element of Argument[0];Property[System.Collections.Generic.KeyValuePair<,>.Value] of Element of ReturnValue;value",
260+
"Newtonsoft.Json.Linq;JObject;false;JObject;(System.Object[]);;Property[System.Collections.Generic.KeyValuePair<,>.Key] of Element of Argument[0];Property[System.Collections.Generic.KeyValuePair<,>.Key] of Element of ReturnValue;value",
261+
"Newtonsoft.Json.Linq;JObject;false;JObject;(System.Object[]);;Property[System.Collections.Generic.KeyValuePair<,>.Value] of Element of Argument[0];Property[System.Collections.Generic.KeyValuePair<,>.Value] of Element of ReturnValue;value",
256262
"Newtonsoft.Json.Linq;JObject;false;Parse;(System.String);;Argument[0];ReturnValue;taint",
257-
"Newtonsoft.Json.Linq;JObject;false;Parse;(System.String,Newtonsoft.Json.Linq.JsonLoadSettings);;Argument[0];ReturnValue;taint"
263+
"Newtonsoft.Json.Linq;JObject;false;Parse;(System.String,Newtonsoft.Json.Linq.JsonLoadSettings);;Argument[0];ReturnValue;taint",
264+
"Newtonsoft.Json.Linq;JObject;false;get_Item;(System.Object);;Element of Argument[-1];ReturnValue;value",
265+
"Newtonsoft.Json.Linq;JObject;false;get_Item;(System.Object);;Property[System.Collections.Generic.KeyValuePair<,>.Value] of Element of Argument[-1];ReturnValue;value",
266+
"Newtonsoft.Json.Linq;JObject;false;get_Item;(System.String);;Element of Argument[-1];ReturnValue;value",
267+
"Newtonsoft.Json.Linq;JObject;false;set_Item;(System.Object,Newtonsoft.Json.Linq.JToken);;Argument[0];Property[System.Collections.Generic.KeyValuePair<,>.Key] of Element of Argument[-1];value",
268+
"Newtonsoft.Json.Linq;JObject;false;set_Item;(System.Object,Newtonsoft.Json.Linq.JToken);;Argument[1];Element of Argument[-1];value",
269+
"Newtonsoft.Json.Linq;JObject;false;set_Item;(System.Object,Newtonsoft.Json.Linq.JToken);;Argument[1];Property[System.Collections.Generic.KeyValuePair<,>.Value] of Element of Argument[-1];value",
270+
"Newtonsoft.Json.Linq;JObject;false;set_Item;(System.String,Newtonsoft.Json.Linq.JToken);;Argument[1];Element of Argument[-1];value",
258271
]
259272
}
260273
}

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

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,3 +71,57 @@ class SystemCollectionsIListInterface extends SystemCollectionsInterface {
7171
class SystemCollectionsIDictionaryInterface extends SystemCollectionsInterface {
7272
SystemCollectionsIDictionaryInterface() { this.hasName("IDictionary") }
7373
}
74+
75+
/** Data flow for `System.Collections.IDictionary`. */
76+
private class SystemCollectionsIDictionaryFlowModelCsv extends SummaryModelCsv {
77+
override predicate row(string row) {
78+
row =
79+
[
80+
"System.Collections;IDictionary;true;Add;(System.Object,System.Object);;Argument[0];Property[System.Collections.Generic.KeyValuePair<,>.Key] of Element of Argument[-1];value",
81+
"System.Collections;IDictionary;true;Add;(System.Object,System.Object);;Argument[1];Property[System.Collections.Generic.KeyValuePair<,>.Value] of Element of Argument[-1];value",
82+
"System.Collections;IDictionary;true;get_Item;(System.Object);;Property[System.Collections.Generic.KeyValuePair<,>.Value] of Element of Argument[-1];ReturnValue;value",
83+
"System.Collections;IDictionary;true;get_Keys;();;Property[System.Collections.Generic.KeyValuePair<,>.Key] of Element of Argument[-1];Element of ReturnValue;value",
84+
"System.Collections;IDictionary;true;get_Values;();;Property[System.Collections.Generic.KeyValuePair<,>.Value] of Element of Argument[-1];Element of ReturnValue;value",
85+
"System.Collections;IDictionary;true;set_Item;(System.Object,System.Object);;Argument[0];Property[System.Collections.Generic.KeyValuePair<,>.Key] of Element of Argument[-1];value",
86+
"System.Collections;IDictionary;true;set_Item;(System.Object,System.Object);;Argument[1];Property[System.Collections.Generic.KeyValuePair<,>.Value] of Element of Argument[-1];value",
87+
]
88+
}
89+
}
90+
91+
/** Data flow for `System.Collections.Hashtable`. */
92+
private class SystemCollectionsHashtableFlowModelCsv extends SummaryModelCsv {
93+
override predicate row(string row) {
94+
row =
95+
[
96+
"System.Collections;Hashtable;false;Clone;();;Element of Argument[0];Element of ReturnValue;value",
97+
"System.Collections;Hashtable;false;Hashtable;(System.Collections.IDictionary);;Property[System.Collections.Generic.KeyValuePair<,>.Key] of Element of Argument[0];Property[System.Collections.Generic.KeyValuePair<,>.Key] of Element of ReturnValue;value",
98+
"System.Collections;Hashtable;false;Hashtable;(System.Collections.IDictionary);;Property[System.Collections.Generic.KeyValuePair<,>.Value] of Element of Argument[0];Property[System.Collections.Generic.KeyValuePair<,>.Value] of Element of ReturnValue;value",
99+
"System.Collections;Hashtable;false;Hashtable;(System.Collections.IDictionary,System.Collections.IEqualityComparer);;Property[System.Collections.Generic.KeyValuePair<,>.Key] of Element of Argument[0];Property[System.Collections.Generic.KeyValuePair<,>.Key] of Element of ReturnValue;value",
100+
"System.Collections;Hashtable;false;Hashtable;(System.Collections.IDictionary,System.Collections.IEqualityComparer);;Property[System.Collections.Generic.KeyValuePair<,>.Value] of Element of Argument[0];Property[System.Collections.Generic.KeyValuePair<,>.Value] of Element of ReturnValue;value",
101+
"System.Collections;Hashtable;false;Hashtable;(System.Collections.IDictionary,System.Collections.IHashCodeProvider,System.Collections.IComparer);;Property[System.Collections.Generic.KeyValuePair<,>.Key] of Element of Argument[0];Property[System.Collections.Generic.KeyValuePair<,>.Key] of Element of ReturnValue;value",
102+
"System.Collections;Hashtable;false;Hashtable;(System.Collections.IDictionary,System.Collections.IHashCodeProvider,System.Collections.IComparer);;Property[System.Collections.Generic.KeyValuePair<,>.Value] of Element of Argument[0];Property[System.Collections.Generic.KeyValuePair<,>.Value] of Element of ReturnValue;value",
103+
"System.Collections;Hashtable;false;Hashtable;(System.Collections.IDictionary,System.Single);;Property[System.Collections.Generic.KeyValuePair<,>.Key] of Element of Argument[0];Property[System.Collections.Generic.KeyValuePair<,>.Key] of Element of ReturnValue;value",
104+
"System.Collections;Hashtable;false;Hashtable;(System.Collections.IDictionary,System.Single);;Property[System.Collections.Generic.KeyValuePair<,>.Value] of Element of Argument[0];Property[System.Collections.Generic.KeyValuePair<,>.Value] of Element of ReturnValue;value",
105+
"System.Collections;Hashtable;false;Hashtable;(System.Collections.IDictionary,System.Single,System.Collections.IEqualityComparer);;Property[System.Collections.Generic.KeyValuePair<,>.Key] of Element of Argument[0];Property[System.Collections.Generic.KeyValuePair<,>.Key] of Element of ReturnValue;value",
106+
"System.Collections;Hashtable;false;Hashtable;(System.Collections.IDictionary,System.Single,System.Collections.IEqualityComparer);;Property[System.Collections.Generic.KeyValuePair<,>.Value] of Element of Argument[0];Property[System.Collections.Generic.KeyValuePair<,>.Value] of Element of ReturnValue;value",
107+
"System.Collections;Hashtable;false;Hashtable;(System.Collections.IDictionary,System.Single,System.Collections.IHashCodeProvider,System.Collections.IComparer);;Property[System.Collections.Generic.KeyValuePair<,>.Key] of Element of Argument[0];Property[System.Collections.Generic.KeyValuePair<,>.Key] of Element of ReturnValue;value",
108+
"System.Collections;Hashtable;false;Hashtable;(System.Collections.IDictionary,System.Single,System.Collections.IHashCodeProvider,System.Collections.IComparer);;Property[System.Collections.Generic.KeyValuePair<,>.Value] of Element of Argument[0];Property[System.Collections.Generic.KeyValuePair<,>.Value] of Element of ReturnValue;value",
109+
]
110+
}
111+
}
112+
113+
/** Data flow for `System.Collections.SortedList`. */
114+
private class SystemCollectionsSortedListFlowModelCsv extends SummaryModelCsv {
115+
override predicate row(string row) {
116+
row =
117+
[
118+
"System.Collections;SortedList;false;Clone;();;Element of Argument[0];Element of ReturnValue;value",
119+
"System.Collections;SortedList;false;GetByIndex;(System.Int32);;Property[System.Collections.Generic.KeyValuePair<,>.Value] of Element of Argument[-1];ReturnValue;value",
120+
"System.Collections;SortedList;false;GetValueList;();;Property[System.Collections.Generic.KeyValuePair<,>.Value] of Element of Argument[-1];Element of ReturnValue;value",
121+
"System.Collections;SortedList;false;SortedList;(System.Collections.IDictionary);;Property[System.Collections.Generic.KeyValuePair<,>.Key] of Element of Argument[0];Property[System.Collections.Generic.KeyValuePair<,>.Key] of Element of ReturnValue;value",
122+
"System.Collections;SortedList;false;SortedList;(System.Collections.IDictionary);;Property[System.Collections.Generic.KeyValuePair<,>.Value] of Element of Argument[0];Property[System.Collections.Generic.KeyValuePair<,>.Value] of Element of ReturnValue;value",
123+
"System.Collections;SortedList;false;SortedList;(System.Collections.IDictionary,System.Collections.IComparer);;Property[System.Collections.Generic.KeyValuePair<,>.Key] of Element of Argument[0];Property[System.Collections.Generic.KeyValuePair<,>.Key] of Element of ReturnValue;value",
124+
"System.Collections;SortedList;false;SortedList;(System.Collections.IDictionary,System.Collections.IComparer);;Property[System.Collections.Generic.KeyValuePair<,>.Value] of Element of Argument[0];Property[System.Collections.Generic.KeyValuePair<,>.Value] of Element of ReturnValue;value",
125+
]
126+
}
127+
}
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
/** Provides definitions for the `System.ComponentModel` namespace. */
2+
3+
private import semmle.code.csharp.dataflow.ExternalFlow
4+
5+
/** Data flow for `System.ComponentModel.PropertyDescriptorCollection`. */
6+
private class SystemComponentModelPropertyDescriptorCollectionFlowModelCsv extends SummaryModelCsv {
7+
override predicate row(string row) {
8+
row =
9+
[
10+
"System.ComponentModel;PropertyDescriptorCollection;false;Add;(System.ComponentModel.PropertyDescriptor);;Argument[0];Element of Argument[-1];value",
11+
"System.ComponentModel;PropertyDescriptorCollection;false;Add;(System.ComponentModel.PropertyDescriptor);;Property[System.Collections.Generic.KeyValuePair<,>.Key] of Argument[0];Property[System.Collections.Generic.KeyValuePair<,>.Key] of Element of Argument[-1];value",
12+
"System.ComponentModel;PropertyDescriptorCollection;false;Add;(System.ComponentModel.PropertyDescriptor);;Property[System.Collections.Generic.KeyValuePair<,>.Value] of Argument[0];Property[System.Collections.Generic.KeyValuePair<,>.Value] of Element of Argument[-1];value",
13+
"System.ComponentModel;PropertyDescriptorCollection;false;Add;(System.Object);;Property[System.Collections.Generic.KeyValuePair<,>.Key] of Argument[0];Property[System.Collections.Generic.KeyValuePair<,>.Key] of Element of Argument[-1];value",
14+
"System.ComponentModel;PropertyDescriptorCollection;false;Add;(System.Object);;Property[System.Collections.Generic.KeyValuePair<,>.Value] of Argument[0];Property[System.Collections.Generic.KeyValuePair<,>.Value] of Element of Argument[-1];value",
15+
"System.ComponentModel;PropertyDescriptorCollection;false;Find;(System.String,System.Boolean);;Element of Argument[-1];ReturnValue;value",
16+
"System.ComponentModel;PropertyDescriptorCollection;false;GetEnumerator;();;Element of Argument[-1];Property[System.Collections.IEnumerator.Current] of ReturnValue;value",
17+
"System.ComponentModel;PropertyDescriptorCollection;false;Insert;(System.Int32,System.ComponentModel.PropertyDescriptor);;Argument[1];Element of Argument[-1];value",
18+
"System.ComponentModel;PropertyDescriptorCollection;false;PropertyDescriptorCollection;(System.ComponentModel.PropertyDescriptor[]);;Property[System.Collections.Generic.KeyValuePair<,>.Key] of Element of Argument[0];Property[System.Collections.Generic.KeyValuePair<,>.Key] of Element of ReturnValue;value",
19+
"System.ComponentModel;PropertyDescriptorCollection;false;PropertyDescriptorCollection;(System.ComponentModel.PropertyDescriptor[]);;Property[System.Collections.Generic.KeyValuePair<,>.Value] of Element of Argument[0];Property[System.Collections.Generic.KeyValuePair<,>.Value] of Element of ReturnValue;value",
20+
"System.ComponentModel;PropertyDescriptorCollection;false;PropertyDescriptorCollection;(System.ComponentModel.PropertyDescriptor[],System.Boolean);;Property[System.Collections.Generic.KeyValuePair<,>.Key] of Element of Argument[0];Property[System.Collections.Generic.KeyValuePair<,>.Key] of Element of ReturnValue;value",
21+
"System.ComponentModel;PropertyDescriptorCollection;false;PropertyDescriptorCollection;(System.ComponentModel.PropertyDescriptor[],System.Boolean);;Property[System.Collections.Generic.KeyValuePair<,>.Value] of Element of Argument[0];Property[System.Collections.Generic.KeyValuePair<,>.Value] of Element of ReturnValue;value",
22+
"System.ComponentModel;PropertyDescriptorCollection;false;get_Item;(System.Int32);;Element of Argument[-1];ReturnValue;value",
23+
"System.ComponentModel;PropertyDescriptorCollection;false;get_Item;(System.Int32);;Property[System.Collections.Generic.KeyValuePair<,>.Value] of Element of Argument[-1];ReturnValue;value",
24+
"System.ComponentModel;PropertyDescriptorCollection;false;get_Item;(System.Object);;Element of Argument[-1];ReturnValue;value",
25+
"System.ComponentModel;PropertyDescriptorCollection;false;get_Item;(System.String);;Element of Argument[-1];ReturnValue;value",
26+
"System.ComponentModel;PropertyDescriptorCollection;false;get_Item;(System.String);;Property[System.Collections.Generic.KeyValuePair<,>.Value] of Element of Argument[-1];ReturnValue;value",
27+
"System.ComponentModel;PropertyDescriptorCollection;false;set_Item;(System.Int32,System.Object);;Argument[0];Property[System.Collections.Generic.KeyValuePair<,>.Key] of Element of Argument[-1];value",
28+
"System.ComponentModel;PropertyDescriptorCollection;false;set_Item;(System.Int32,System.Object);;Argument[1];Property[System.Collections.Generic.KeyValuePair<,>.Value] of Element of Argument[-1];value",
29+
"System.ComponentModel;PropertyDescriptorCollection;false;set_Item;(System.Object,System.Object);;Argument[1];Element of Argument[-1];value",
30+
]
31+
}
32+
}

0 commit comments

Comments
 (0)