Skip to content

Commit bcbda90

Browse files
committed
Java: Extend neutrals with a kind column and introduce validation.
1 parent 4ac0396 commit bcbda90

File tree

4 files changed

+17
-10
lines changed

4 files changed

+17
-10
lines changed

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

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
* - Summaries:
1313
* `package; type; subtypes; name; signature; ext; input; output; kind; provenance`
1414
* - Neutrals:
15-
* `package; type; name; signature; provenance`
15+
* `package; type; name; signature; kind; provenance`
1616
* A neutral is used to indicate that there is no flow via a callable.
1717
*
1818
* The interpretation of a row is similar to API-graphs with a left-to-right
@@ -65,7 +65,9 @@
6565
* which classes the interpreted elements should be added. For example, for
6666
* sources "remote" indicates a default remote flow source, and for summaries
6767
* "taint" indicates a default additional taint step and "value" indicates a
68-
* globally applicable value-preserving step.
68+
* globally applicable value-preserving step. For neutrals the kind can be `summary`,
69+
* `source` or `sink` to indicate that the neutral is neutral with respect to
70+
* flow (no summary), source (is not a source) or sink (is not a sink).
6971
* 9. The `provenance` column is a tag to indicate the origin and verification of a model.
7072
* The format is {origin}-{verification} or just "manual" where the origin describes
7173
* the origin of the model and verification describes how the model has been verified.
@@ -165,7 +167,7 @@ predicate summaryModel(
165167
}
166168

167169
/** Holds if a neutral model exists indicating there is no flow for the given parameters. */
168-
predicate neutralModel = Extensions::neutralModel/5;
170+
predicate neutralModel = Extensions::neutralModel/6;
169171

170172
private predicate relevantPackage(string package) {
171173
sourceModel(package, _, _, _, _, _, _, _, _) or
@@ -288,6 +290,11 @@ module ModelValidation {
288290
not kind.matches("qltest%") and
289291
result = "Invalid kind \"" + kind + "\" in source model."
290292
)
293+
or
294+
exists(string kind | neutralModel(_, _, _, _, kind, _) |
295+
not kind = ["summary", "source", "sink"] and
296+
result = "Invalid kind \"" + kind + "\" in neutral model."
297+
)
291298
}
292299

293300
private string getInvalidModelSignature() {
@@ -302,7 +309,7 @@ module ModelValidation {
302309
summaryModel(package, type, _, name, signature, ext, _, _, _, provenance) and
303310
pred = "summary"
304311
or
305-
neutralModel(package, type, name, signature, provenance) and
312+
neutralModel(package, type, name, signature, _, provenance) and
306313
ext = "" and
307314
pred = "neutral"
308315
|
@@ -346,7 +353,7 @@ private predicate elementSpec(
346353
or
347354
summaryModel(package, type, subtypes, name, signature, ext, _, _, _, _)
348355
or
349-
neutralModel(package, type, name, signature, _) and ext = "" and subtypes = false
356+
neutralModel(package, type, name, signature, _, _) and ext = "" and subtypes = false
350357
}
351358

352359
/**

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ extensible predicate summaryModel(
3030
* Holds if a neutral model exists indicating there is no flow for the given parameters.
3131
*/
3232
extensible predicate neutralModel(
33-
string package, string type, string name, string signature, string provenance
33+
string package, string type, string name, string signature, string kind, string provenance
3434
);
3535

3636
/**

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -335,7 +335,7 @@ module Public {
335335
class NeutralCallable extends SummarizedCallableBase {
336336
private Provenance provenance;
337337

338-
NeutralCallable() { neutralElement(this, provenance) }
338+
NeutralCallable() { neutralSummaryElement(this, provenance) }
339339

340340
/**
341341
* Holds if the neutral is auto generated.

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -154,12 +154,12 @@ predicate summaryElement(
154154
}
155155

156156
/**
157-
* Holds if a neutral model exists for `c` with provenance `provenance`,
157+
* Holds if a neutral summary model exists for `c` with provenance `provenance`,
158158
* which means that there is no flow through `c`.
159159
*/
160-
predicate neutralElement(SummarizedCallableBase c, string provenance) {
160+
predicate neutralSummaryElement(SummarizedCallableBase c, string provenance) {
161161
exists(string namespace, string type, string name, string signature |
162-
neutralModel(namespace, type, name, signature, provenance) and
162+
neutralModel(namespace, type, name, signature, "summary", provenance) and
163163
c.asCallable() = interpretElement(namespace, type, false, name, signature, "")
164164
)
165165
}

0 commit comments

Comments
 (0)