Skip to content

Commit 46ef954

Browse files
committed
Java: Validate all accesspaths except for Field.
1 parent 6c0c06c commit 46ef954

File tree

3 files changed

+22
-5
lines changed

3 files changed

+22
-5
lines changed

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)