Skip to content

Commit 4dcfb4d

Browse files
committed
C#: Extend neutrals with a kind column and introduce validation.
1 parent 9558522 commit 4dcfb4d

File tree

4 files changed

+17
-10
lines changed

4 files changed

+17
-10
lines changed

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

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
* - Summaries:
1313
* `namespace; type; subtypes; name; signature; ext; input; output; kind; provenance`
1414
* - Neutrals:
15-
* `namespace; type; name; signature; provenance`
15+
* `namespace; 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
@@ -72,7 +72,9 @@
7272
* which classes the interpreted elements should be added. For example, for
7373
* sources "remote" indicates a default remote flow source, and for summaries
7474
* "taint" indicates a default additional taint step and "value" indicates a
75-
* globally applicable value-preserving step.
75+
* globally applicable value-preserving step. For neutrals the kind can be `summary`,
76+
* `source` or `sink` to indicate that the neutral is neutral with respect to
77+
* flow (no summary), source (is not a source) or sink (is not a sink).
7678
* 9. The `provenance` column is a tag to indicate the origin and verification of a model.
7779
* The format is {origin}-{verification} or just "manual" where the origin describes
7880
* the origin of the model and verification describes how the model has been verified.
@@ -104,7 +106,7 @@ predicate sinkModel = Extensions::sinkModel/9;
104106
predicate summaryModel = Extensions::summaryModel/10;
105107

106108
/** Holds if a model exists indicating there is no flow for the given parameters. */
107-
predicate neutralModel = Extensions::neutralModel/5;
109+
predicate neutralModel = Extensions::neutralModel/6;
108110

109111
private predicate relevantNamespace(string namespace) {
110112
sourceModel(namespace, _, _, _, _, _, _, _, _) or
@@ -218,6 +220,11 @@ module ModelValidation {
218220
not kind = ["local", "remote", "file", "file-write"] and
219221
result = "Invalid kind \"" + kind + "\" in source model."
220222
)
223+
or
224+
exists(string kind | neutralModel(_, _, _, _, kind, _) |
225+
not kind = ["summary", "source", "sink"] and
226+
result = "Invalid kind \"" + kind + "\" in neutral model."
227+
)
221228
}
222229

223230
private string getInvalidModelSignature() {
@@ -232,7 +239,7 @@ module ModelValidation {
232239
summaryModel(namespace, type, _, name, signature, ext, _, _, _, provenance) and
233240
pred = "summary"
234241
or
235-
neutralModel(namespace, type, name, signature, provenance) and
242+
neutralModel(namespace, type, name, signature, _, provenance) and
236243
ext = "" and
237244
pred = "neutral"
238245
|
@@ -275,7 +282,7 @@ private predicate elementSpec(
275282
or
276283
summaryModel(namespace, type, subtypes, name, signature, ext, _, _, _, _)
277284
or
278-
neutralModel(namespace, type, name, signature, _) and ext = "" and subtypes = false
285+
neutralModel(namespace, type, name, signature, _, _) and ext = "" and subtypes = false
279286
}
280287

281288
private predicate elementSpec(

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

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

csharp/ql/lib/semmle/code/csharp/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.

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -111,12 +111,12 @@ predicate summaryElement(Callable c, string input, string output, string kind, s
111111
}
112112

113113
/**
114-
* Holds if a neutral model exists for `c` with provenance `provenace`,
114+
* Holds if a neutral summary model exists for `c` with provenance `provenace`,
115115
* which means that there is no flow through `c`.
116116
*/
117-
predicate neutralElement(Callable c, string provenance) {
117+
predicate neutralSummaryElement(Callable c, string provenance) {
118118
exists(string namespace, string type, string name, string signature |
119-
neutralModel(namespace, type, name, signature, provenance) and
119+
neutralModel(namespace, type, name, signature, "summary", provenance) and
120120
c = interpretElement(namespace, type, false, name, signature, "")
121121
)
122122
}

0 commit comments

Comments
 (0)