Skip to content

Commit 915efff

Browse files
authored
Merge pull request github#12610 from michaelnebel/java/validatespecs
Java/C#: Validate all AccessPaths.
2 parents 0f267e0 + 71d184e commit 915efff

File tree

6 files changed

+43
-9
lines changed

6 files changed

+43
-9
lines changed

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

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,7 @@ predicate modelCoverage(string namespace, int namespaces, string kind, string pa
160160
/** Provides a query predicate to check the MaD models for validation errors. */
161161
module ModelValidation {
162162
private string getInvalidModelInput() {
163-
exists(string pred, AccessPath input, string part |
163+
exists(string pred, AccessPath input, AccessPathToken part |
164164
sinkModel(_, _, _, _, _, _, input, _, _) and pred = "sink"
165165
or
166166
summaryModel(_, _, _, _, _, _, input, _, _, _) and pred = "summary"
@@ -169,7 +169,8 @@ module ModelValidation {
169169
invalidSpecComponent(input, part) and
170170
not part = "" and
171171
not (part = "Argument" and pred = "sink") and
172-
not parseArg(part, _)
172+
not parseArg(part, _) and
173+
not part.getName() = ["Field", "Property"]
173174
or
174175
part = input.getToken(_) and
175176
parseParam(part, _)
@@ -181,15 +182,16 @@ module ModelValidation {
181182
}
182183

183184
private string getInvalidModelOutput() {
184-
exists(string pred, string output, string part |
185+
exists(string pred, AccessPath output, AccessPathToken part |
185186
sourceModel(_, _, _, _, _, _, output, _, _) and pred = "source"
186187
or
187188
summaryModel(_, _, _, _, _, _, _, output, _, _) and pred = "summary"
188189
|
189190
(
190191
invalidSpecComponent(output, part) and
191192
not part = "" and
192-
not (part = ["Argument", "Parameter"] and pred = "source")
193+
not (part = ["Argument", "Parameter"] and pred = "source") and
194+
not part.getName() = ["Field", "Property"]
193195
or
194196
invalidIndexComponent(output, part)
195197
) and

csharp/ql/test/library-tests/dataflow/external-models/validatemodels.expected

Whitespace-only changes.
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
import csharp
2+
import semmle.code.csharp.dataflow.ExternalFlow
3+
import semmle.code.csharp.dataflow.internal.AccessPathSyntax
4+
import ModelValidation
5+
6+
private predicate getRelevantAccessPath(string path) {
7+
summaryModel(_, _, _, _, _, _, path, _, _, _) or
8+
summaryModel(_, _, _, _, _, _, _, path, _, _) or
9+
sinkModel(_, _, _, _, _, _, path, _, _) or
10+
sourceModel(_, _, _, _, _, _, path, _, _)
11+
}
12+
13+
private class AccessPathsExternal extends AccessPath::Range {
14+
AccessPathsExternal() { getRelevantAccessPath(this) }
15+
}

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

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -220,7 +220,7 @@ predicate modelCoverage(string package, int pkgs, string kind, string part, int
220220
/** Provides a query predicate to check the MaD models for validation errors. */
221221
module ModelValidation {
222222
private string getInvalidModelInput() {
223-
exists(string pred, string input, string part |
223+
exists(string pred, AccessPath input, AccessPathToken part |
224224
sinkModel(_, _, _, _, _, _, input, _, _) and pred = "sink"
225225
or
226226
summaryModel(_, _, _, _, _, _, input, _, _, _) and pred = "summary"
@@ -229,9 +229,10 @@ module ModelValidation {
229229
invalidSpecComponent(input, part) and
230230
not part = "" and
231231
not (part = "Argument" and pred = "sink") and
232-
not parseArg(part, _)
232+
not parseArg(part, _) and
233+
not part.getName() = "Field"
233234
or
234-
part = input.(AccessPath).getToken(0) and
235+
part = input.getToken(0) and
235236
parseParam(part, _)
236237
or
237238
invalidIndexComponent(input, part)
@@ -241,15 +242,16 @@ module ModelValidation {
241242
}
242243

243244
private string getInvalidModelOutput() {
244-
exists(string pred, string output, string part |
245+
exists(string pred, AccessPath output, AccessPathToken part |
245246
sourceModel(_, _, _, _, _, _, output, _, _) and pred = "source"
246247
or
247248
summaryModel(_, _, _, _, _, _, _, output, _, _) and pred = "summary"
248249
|
249250
(
250251
invalidSpecComponent(output, part) and
251252
not part = "" and
252-
not (part = ["Argument", "Parameter"] and pred = "source")
253+
not (part = ["Argument", "Parameter"] and pred = "source") and
254+
not part.getName() = "Field"
253255
or
254256
invalidIndexComponent(output, part)
255257
) and

java/ql/test/library-tests/dataflow/external-models/validatemodels.expected

Whitespace-only changes.
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
import java
2+
import semmle.code.java.dataflow.ExternalFlow
3+
import semmle.code.java.dataflow.internal.AccessPathSyntax
4+
import ModelValidation
5+
6+
private predicate getRelevantAccessPath(string path) {
7+
summaryModel(_, _, _, _, _, _, path, _, _, _) or
8+
summaryModel(_, _, _, _, _, _, _, path, _, _) or
9+
sinkModel(_, _, _, _, _, _, path, _, _) or
10+
sourceModel(_, _, _, _, _, _, path, _, _)
11+
}
12+
13+
private class AccessPathsExternal extends AccessPath::Range {
14+
AccessPathsExternal() { getRelevantAccessPath(this) }
15+
}

0 commit comments

Comments
 (0)