Skip to content

Commit 3983587

Browse files
committed
C#: Set literals.
1 parent 2e61ae2 commit 3983587

File tree

14 files changed

+108
-460
lines changed

14 files changed

+108
-460
lines changed

csharp/ql/lib/semmle/code/csharp/Modifier.qll

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,5 @@ class Modifier extends Element, @modifier {
1919
* An access modifier: `public`, `private`, `internal` or `protected`.
2020
*/
2121
class AccessModifier extends Modifier {
22-
AccessModifier() {
23-
hasName("public") or
24-
hasName("private") or
25-
hasName("internal") or
26-
hasName("protected")
27-
}
22+
AccessModifier() { hasName(["public", "private", "internal", "protected"]) }
2823
}

csharp/ql/lib/semmle/code/csharp/commons/Collections.qll

Lines changed: 28 additions & 75 deletions
Original file line numberDiff line numberDiff line change
@@ -3,23 +3,12 @@
33
import csharp
44

55
private string modifyMethodName() {
6-
result = "Add" or
7-
result = "AddFirst" or
8-
result = "AddLast" or
9-
result = "Clear" or
10-
result = "Enqueue" or
11-
result = "ExceptWith" or
12-
result = "Insert" or
13-
result = "IntersectWith" or
14-
result = "Push" or
15-
result = "Remove" or
16-
result = "RemoveAt" or
17-
result = "RemoveFirst" or
18-
result = "RemoveLast" or
19-
result = "Set" or
20-
result = "SetAll" or
21-
result = "SymmetricExceptWith" or
22-
result = "UnionWith"
6+
result =
7+
[
8+
"Add", "AddFirst", "AddLast", "Clear", "Enqueue", "ExceptWith", "Insert", "IntersectWith",
9+
"Push", "Remove", "RemoveAt", "RemoveFirst", "RemoveLast", "Set", "SetAll",
10+
"SymmetricExceptWith", "UnionWith"
11+
]
2312
}
2413

2514
/** A method call that modifies a collection. */
@@ -39,45 +28,27 @@ class CollectionModificationAccess extends Access {
3928
}
4029

4130
private string collectionTypeName() {
42-
result = "ArrayList" or
43-
result = "BitArray" or
44-
result = "Hashtable" or
45-
result = "ICollection" or
46-
result = "IDictionary" or
47-
result = "IList" or
48-
result = "Queue" or
49-
result = "ReadOnlyCollectionBase" or
50-
result = "SortedList" or
51-
result = "Stack"
31+
result =
32+
[
33+
"ArrayList", "BitArray", "Hashtable", "ICollection", "IDictionary", "IList", "Queue",
34+
"ReadOnlyCollectionBase", "SortedList", "Stack"
35+
]
5236
}
5337

54-
private string collectionNamespaceName() {
55-
result = "Mono.Collections" or
56-
result = "System.Collections"
57-
}
38+
private string collectionNamespaceName() { result = ["Mono.Collections", "System.Collections"] }
5839

5940
private string genericCollectionNamespaceName() {
60-
result = "Mono.Collections.Generic" or
61-
result = "System.Collections.Generic"
41+
result = ["Mono.Collections.Generic", "System.Collections.Generic"]
6242
}
6343

6444
private string genericCollectionTypeName() {
65-
result = "Dictionary<,>" or
66-
result = "HashSet<>" or
67-
result = "ICollection<>" or
68-
result = "IDictionary<,>" or
69-
result = "IList<>" or
70-
result = "ISet<>" or
71-
result = "LinkedList<>" or
72-
result = "List<>" or
73-
result = "Queue<>" or
74-
result = "SortedDictionary<,>" or
75-
result = "SortedList<,>" or
76-
result = "SortedSet<>" or
77-
result = "Stack<>" or
78-
result = "SynchronizedCollection<>" or
79-
result = "SynchronizedKeyedCollection<>" or
80-
result = "SynchronizedReadOnlyCollection<>"
45+
result =
46+
[
47+
"Dictionary<,>", "HashSet<>", "ICollection<>", "IDictionary<,>", "IList<>", "ISet<>",
48+
"LinkedList<>", "List<>", "Queue<>", "SortedDictionary<,>", "SortedList<,>", "SortedSet<>",
49+
"Stack<>", "SynchronizedCollection<>", "SynchronizedKeyedCollection<>",
50+
"SynchronizedReadOnlyCollection<>"
51+
]
8152
}
8253

8354
/** A collection type. */
@@ -105,36 +76,18 @@ class EmptyCollectionCreation extends ObjectCreation {
10576
}
10677

10778
private string readonlyMethodName() {
108-
result = "BinarySearch" or
109-
result = "Clone" or
110-
result = "Contains" or
111-
result = "ContainsKey" or
112-
result = "ContainsValue" or
113-
result = "CopyTo" or
114-
result = "Equals" or
115-
result = "FixedArray" or
116-
result = "FixedSize" or
117-
result = "Get" or
118-
result = "GetEnumerator" or
119-
result = "GetHashCode" or
120-
result = "GetRange" or
121-
result = "IndexOf" or
122-
result = "IsProperSubsetOf" or
123-
result = "IsProperSupersetOf" or
124-
result = "IsSubsetOf" or
125-
result = "IsSupersetOf" or
126-
result = "LastIndexOf" or
127-
result = "MemberwiseClone" or
128-
result = "Peek" or
129-
result = "ToArray" or
130-
result = "ToString" or
131-
result = "TryGetValue"
79+
result =
80+
[
81+
"BinarySearch", "Clone", "Contains", "ContainsKey", "ContainsValue", "CopyTo", "Equals",
82+
"FixedArray", "FixedSize", "Get", "GetEnumerator", "GetHashCode", "GetRange", "IndexOf",
83+
"IsProperSubsetOf", "IsProperSupersetOf", "IsSubsetOf", "IsSupersetOf", "LastIndexOf",
84+
"MemberwiseClone", "Peek", "ToArray", "ToString", "TryGetValue"
85+
]
13286
}
13387

13488
private string noAddMethodName() {
13589
result = readonlyMethodName() or
136-
result = "Dequeue" or
137-
result = "Pop"
90+
result = ["Dequeue", "Pop"]
13891
}
13992

14093
/** Holds if `a` is an access that does not modify a collection. */

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

Lines changed: 8 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -120,21 +120,13 @@ module JsonNET {
120120
SerializedMember() {
121121
// This member has a Json attribute
122122
exists(Class attribute | attribute = this.getAnAttribute().getType() |
123-
attribute.hasName("JsonPropertyAttribute")
124-
or
125-
attribute.hasName("JsonDictionaryAttribute")
126-
or
127-
attribute.hasName("JsonRequiredAttribute")
128-
or
129-
attribute.hasName("JsonArrayAttribute")
130-
or
131-
attribute.hasName("JsonConverterAttribute")
132-
or
133-
attribute.hasName("JsonExtensionDataAttribute")
134-
or
135-
attribute.hasName("SerializableAttribute") // System.SerializableAttribute
136-
or
137-
attribute.hasName("DataMemberAttribute") // System.DataMemberAttribute
123+
attribute
124+
.hasName([
125+
"JsonPropertyAttribute", "JsonDictionaryAttribute", "JsonRequiredAttribute",
126+
"JsonArrayAttribute", "JsonConverterAttribute", "JsonExtensionDataAttribute",
127+
"SerializableAttribute", // System.SerializableAttribute
128+
"DataMemberAttribute" // System.DataMemberAttribute
129+
])
138130
)
139131
or
140132
// This field is a member of an explicitly serialized type
@@ -175,7 +167,7 @@ module JsonNET {
175167
/** Any attribute class that marks a member to not be serialized. */
176168
private class NotSerializedAttributeClass extends JsonClass {
177169
NotSerializedAttributeClass() {
178-
this.hasName("JsonIgnoreAttribute") or this.hasName("NonSerializedAttribute")
170+
this.hasName(["JsonIgnoreAttribute", "NonSerializedAttribute"])
179171
}
180172
}
181173

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

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -28,15 +28,7 @@ module NHibernate {
2828

2929
/** Gets a type parameter that specifies a mapped class. */
3030
TypeParameter getAMappedObjectTp() {
31-
exists(string methodName |
32-
methodName = "Load<>"
33-
or
34-
methodName = "Merge<>"
35-
or
36-
methodName = "Get<>"
37-
or
38-
methodName = "Query<>"
39-
|
31+
exists(string methodName | methodName = ["Load<>", "Merge<>", "Get<>", "Query<>"] |
4032
result = this.getAMethod(methodName).(UnboundGenericMethod).getTypeParameter(0)
4133
)
4234
}

csharp/ql/lib/semmle/code/csharp/security/PrivateData.qll

Lines changed: 16 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -14,26 +14,22 @@ import semmle.code.csharp.frameworks.system.windows.Forms
1414

1515
/** A string for `match` that identifies strings that look like they represent private data. */
1616
private string privateNames() {
17-
// Inspired by the list on https://cwe.mitre.org/data/definitions/359.html
18-
// Government identifiers, such as Social Security Numbers
19-
result = "%social%security%number%" or
20-
// Contact information, such as home addresses and telephone numbers
21-
result = "%postcode%" or
22-
result = "%zipcode%" or
23-
result = "%telephone%" or
24-
// Geographic location - where the user is (or was)
25-
result = "%latitude%" or
26-
result = "%longitude%" or
27-
// Financial data - such as credit card numbers, salary, bank accounts, and debts
28-
result = "%creditcard%" or
29-
result = "%salary%" or
30-
result = "%bankaccount%" or
31-
// Communications - e-mail addresses, private e-mail messages, SMS text messages, chat logs, etc.
32-
result = "%email%" or
33-
result = "%mobile%" or
34-
result = "%employer%" or
35-
// Health - medical conditions, insurance status, prescription records
36-
result = "%medical%"
17+
result =
18+
[
19+
// Inspired by the list on https://cwe.mitre.org/data/definitions/359.html
20+
// Government identifiers, such as Social Security Numbers
21+
"%social%security%number%",
22+
// Contact information, such as home addresses and telephone numbers
23+
"%postcode%", "%zipcode%", "%telephone%",
24+
// Geographic location - where the user is (or was)
25+
"%latitude%", "%longitude%",
26+
// Financial data - such as credit card numbers, salary, bank accounts, and debts
27+
"%creditcard%", "%salary%", "%bankaccount%",
28+
// Communications - e-mail addresses, private e-mail messages, SMS text messages, chat logs, etc.
29+
"%email%", "%mobile%", "%employer%",
30+
// Health - medical conditions, insurance status, prescription records
31+
"%medical%"
32+
]
3733
}
3834

3935
/** An expression that might contain private data. */

csharp/ql/lib/semmle/code/csharp/security/dataflow/flowsinks/ExternalLocationSink.qll

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -38,12 +38,7 @@ class TraceMessageSink extends ExternalLocationSink {
3838
trace.hasQualifiedName("System.Diagnostics", "TraceSource")
3939
|
4040
this.getExpr() = trace.getAMethod().getACall().getArgumentForName(parameterName) and
41-
(
42-
parameterName = "format" or
43-
parameterName = "args" or
44-
parameterName = "message" or
45-
parameterName = "category"
46-
)
41+
parameterName = ["format", "args", "message", "category"]
4742
)
4843
}
4944
}

csharp/ql/lib/semmle/code/csharp/security/dataflow/flowsources/Remote.qll

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -43,15 +43,7 @@ class AspNetQueryStringMember extends Member {
4343
* request.
4444
*/
4545
private string getHttpRequestFlowPropertyNames() {
46-
result = "QueryString" or
47-
result = "Headers" or
48-
result = "RawUrl" or
49-
result = "Url" or
50-
result = "Cookies" or
51-
result = "Form" or
52-
result = "Params" or
53-
result = "Path" or
54-
result = "PathInfo"
46+
result = ["QueryString", "Headers", "RawUrl", "Url", "Cookies", "Form", "Params", "Path", "PathInfo"]
5547
}
5648

5749
/** A data flow source of remote user input (ASP.NET query string). */

0 commit comments

Comments
 (0)