Skip to content

Commit eb27e8a

Browse files
committed
C#: Prepare ExternalFlow for converting model predicates into extensible predicates.
1 parent ac47b56 commit eb27e8a

File tree

1 file changed

+94
-25
lines changed

1 file changed

+94
-25
lines changed

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

Lines changed: 94 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -179,25 +179,23 @@ class NegativeSummaryModelCsv extends Unit {
179179
abstract predicate row(string row);
180180
}
181181

182-
/** Holds if `row` is a source model. */
183-
predicate sourceModel(string row) { any(SourceModelCsv s).row(row) }
182+
private predicate sourceModelInternal(string row) { any(SourceModelCsv s).row(row) }
184183

185-
/** Holds if `row` is a sink model. */
186-
predicate sinkModel(string row) { any(SinkModelCsv s).row(row) }
184+
private predicate summaryModelInternal(string row) { any(SummaryModelCsv s).row(row) }
187185

188-
/** Holds if `row` is a summary model. */
189-
predicate summaryModel(string row) { any(SummaryModelCsv s).row(row) }
186+
private predicate sinkModelInternal(string row) { any(SinkModelCsv s).row(row) }
190187

191-
/** Holds if `row` is a negative summary model. */
192-
predicate negativeSummaryModel(string row) { any(NegativeSummaryModelCsv s).row(row) }
188+
private predicate negativeSummaryModelInternal(string row) {
189+
any(NegativeSummaryModelCsv s).row(row)
190+
}
193191

194192
/** Holds if a source model exists for the given parameters. */
195193
predicate sourceModel(
196194
string namespace, string type, boolean subtypes, string name, string signature, string ext,
197195
string output, string kind, string provenance
198196
) {
199197
exists(string row |
200-
sourceModel(row) and
198+
sourceModelInternal(row) and
201199
row.splitAt(";", 0) = namespace and
202200
row.splitAt(";", 1) = type and
203201
row.splitAt(";", 2) = subtypes.toString() and
@@ -211,13 +209,33 @@ predicate sourceModel(
211209
)
212210
}
213211

212+
/** Holds if `row` is a source model. */
213+
predicate sourceModel(string row) {
214+
exists(
215+
string namespace, string type, boolean subtypes, string name, string signature, string ext,
216+
string output, string kind, string provenance
217+
|
218+
sourceModel(namespace, type, subtypes, name, signature, ext, output, kind, provenance) and
219+
row =
220+
namespace + ";" //
221+
+ type + ";" //
222+
+ subtypes.toString() + ";" //
223+
+ name + ";" //
224+
+ signature + ";" //
225+
+ ext + ";" //
226+
+ output + ";" //
227+
+ kind + ";" //
228+
+ provenance
229+
)
230+
}
231+
214232
/** Holds if a sink model exists for the given parameters. */
215233
predicate sinkModel(
216234
string namespace, string type, boolean subtypes, string name, string signature, string ext,
217235
string input, string kind, string provenance
218236
) {
219237
exists(string row |
220-
sinkModel(row) and
238+
sinkModelInternal(row) and
221239
row.splitAt(";", 0) = namespace and
222240
row.splitAt(";", 1) = type and
223241
row.splitAt(";", 2) = subtypes.toString() and
@@ -231,13 +249,33 @@ predicate sinkModel(
231249
)
232250
}
233251

252+
/** Holds if `row` is a sink model. */
253+
predicate sinkModel(string row) {
254+
exists(
255+
string namespace, string type, boolean subtypes, string name, string signature, string ext,
256+
string input, string kind, string provenance
257+
|
258+
sinkModel(namespace, type, subtypes, name, signature, ext, input, kind, provenance) and
259+
row =
260+
namespace + ";" //
261+
+ type + ";" //
262+
+ subtypes.toString() + ";" //
263+
+ name + ";" //
264+
+ signature + ";" //
265+
+ ext + ";" //
266+
+ input + ";" //
267+
+ kind + ";" //
268+
+ provenance
269+
)
270+
}
271+
234272
/** Holds if a summary model exists for the given parameters. */
235273
predicate summaryModel(
236274
string namespace, string type, boolean subtypes, string name, string signature, string ext,
237275
string input, string output, string kind, string provenance
238276
) {
239277
exists(string row |
240-
summaryModel(row) and
278+
summaryModelInternal(row) and
241279
row.splitAt(";", 0) = namespace and
242280
row.splitAt(";", 1) = type and
243281
row.splitAt(";", 2) = subtypes.toString() and
@@ -252,12 +290,33 @@ predicate summaryModel(
252290
)
253291
}
254292

293+
/** Holds if `row` is a summary model. */
294+
predicate summaryModel(string row) {
295+
exists(
296+
string namespace, string type, boolean subtypes, string name, string signature, string ext,
297+
string input, string output, string kind, string provenance
298+
|
299+
summaryModel(namespace, type, subtypes, name, signature, ext, input, output, kind, provenance) and
300+
row =
301+
namespace + ";" //
302+
+ type + ";" //
303+
+ subtypes.toString() + ";" //
304+
+ name + ";" //
305+
+ signature + ";" //
306+
+ ext + ";" //
307+
+ input + ";" //
308+
+ output + ";" //
309+
+ kind + ";" //
310+
+ provenance
311+
)
312+
}
313+
255314
/** Holds if a summary model exists indicating there is no flow for the given parameters. */
256315
predicate negativeSummaryModel(
257316
string namespace, string type, string name, string signature, string provenance
258317
) {
259318
exists(string row |
260-
negativeSummaryModel(row) and
319+
negativeSummaryModelInternal(row) and
261320
row.splitAt(";", 0) = namespace and
262321
row.splitAt(";", 1) = type and
263322
row.splitAt(";", 2) = name and
@@ -266,6 +325,19 @@ predicate negativeSummaryModel(
266325
)
267326
}
268327

328+
/** Holds if `row` is a negative summary model. */
329+
predicate negativeSummaryModel(string row) {
330+
exists(string namespace, string type, string name, string signature, string provenance |
331+
negativeSummaryModel(namespace, type, name, signature, provenance) and
332+
row =
333+
namespace + ";" //
334+
+ type + ";" //
335+
+ name + ";" //
336+
+ signature + ";" //
337+
+ provenance
338+
)
339+
}
340+
269341
private predicate relevantNamespace(string namespace) {
270342
sourceModel(namespace, _, _, _, _, _, _, _, _) or
271343
sinkModel(namespace, _, _, _, _, _, _, _, _) or
@@ -355,33 +427,30 @@ module CsvValidation {
355427
}
356428

357429
private string getInvalidModelKind() {
358-
exists(string row, string kind | summaryModel(row) |
359-
kind = row.splitAt(";", 8) and
430+
exists(string kind | summaryModel(_, _, _, _, _, _, _, _, kind, _) |
360431
not kind = ["taint", "value"] and
361432
result = "Invalid kind \"" + kind + "\" in summary model."
362433
)
363434
or
364-
exists(string row, string kind | sinkModel(row) |
365-
kind = row.splitAt(";", 7) and
435+
exists(string kind | sinkModel(_, _, _, _, _, _, _, kind, _) |
366436
not kind = ["code", "sql", "xss", "remote", "html"] and
367437
not kind.matches("encryption-%") and
368438
result = "Invalid kind \"" + kind + "\" in sink model."
369439
)
370440
or
371-
exists(string row, string kind | sourceModel(row) |
372-
kind = row.splitAt(";", 7) and
441+
exists(string kind | sourceModel(_, _, _, _, _, _, _, kind, _) |
373442
not kind = ["local", "file"] and
374443
result = "Invalid kind \"" + kind + "\" in source model."
375444
)
376445
}
377446

378447
private string getInvalidModelSubtype() {
379448
exists(string pred, string row |
380-
sourceModel(row) and pred = "source"
449+
sourceModelInternal(row) and pred = "source"
381450
or
382-
sinkModel(row) and pred = "sink"
451+
sinkModelInternal(row) and pred = "sink"
383452
or
384-
summaryModel(row) and pred = "summary"
453+
summaryModelInternal(row) and pred = "summary"
385454
|
386455
exists(string b |
387456
b = row.splitAt(";", 2) and
@@ -393,13 +462,13 @@ module CsvValidation {
393462

394463
private string getInvalidModelColumnCount() {
395464
exists(string pred, string row, int expect |
396-
sourceModel(row) and expect = 9 and pred = "source"
465+
sourceModelInternal(row) and expect = 9 and pred = "source"
397466
or
398-
sinkModel(row) and expect = 9 and pred = "sink"
467+
sinkModelInternal(row) and expect = 9 and pred = "sink"
399468
or
400-
summaryModel(row) and expect = 10 and pred = "summary"
469+
summaryModelInternal(row) and expect = 10 and pred = "summary"
401470
or
402-
negativeSummaryModel(row) and expect = 5 and pred = "negative summary"
471+
negativeSummaryModelInternal(row) and expect = 5 and pred = "negative summary"
403472
|
404473
exists(int cols |
405474
cols = 1 + max(int n | exists(row.splitAt(";", n))) and

0 commit comments

Comments
 (0)