Skip to content

Commit 0ec5620

Browse files
committed
Java: Introduce index validation.
1 parent 9a3c2d3 commit 0ec5620

File tree

2 files changed

+19
-3
lines changed

2 files changed

+19
-3
lines changed

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

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -233,6 +233,8 @@ module ModelValidation {
233233
or
234234
part = input.(AccessPath).getToken(0) and
235235
parseParam(part, _)
236+
or
237+
invalidIndexComponent(input, part)
236238
) and
237239
result = "Unrecognized input specification \"" + part + "\" in " + pred + " model."
238240
)
@@ -244,9 +246,13 @@ module ModelValidation {
244246
or
245247
summaryModel(_, _, _, _, _, _, _, output, _, _) and pred = "summary"
246248
|
247-
invalidSpecComponent(output, part) and
248-
not part = "" and
249-
not (part = ["Argument", "Parameter"] and pred = "source") and
249+
(
250+
invalidSpecComponent(output, part) and
251+
not part = "" and
252+
not (part = ["Argument", "Parameter"] and pred = "source")
253+
or
254+
invalidIndexComponent(output, part)
255+
) and
250256
result = "Unrecognized output specification \"" + part + "\" in " + pred + " model."
251257
)
252258
}

java/ql/lib/semmle/code/java/dataflow/internal/FlowSummaryImpl.qll

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1050,6 +1050,16 @@ module Private {
10501050
not exists(interpretComponent(c))
10511051
}
10521052

1053+
/**
1054+
* Holds if token `part` of specification `spec` has an invalid index.
1055+
* E.g., `Argument[-1]`.
1056+
*/
1057+
predicate invalidIndexComponent(AccessPath spec, AccessPathToken part) {
1058+
part = spec.getToken(_) and
1059+
part.getName() = ["Parameter", "Argument"] and
1060+
AccessPath::parseInt(part.getArgumentList()) < 0
1061+
}
1062+
10531063
private predicate inputNeedsReference(AccessPathToken c) {
10541064
c.getName() = "Argument" or
10551065
inputNeedsReferenceSpecific(c)

0 commit comments

Comments
 (0)