Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 37976d5

Browse files
committed
C#/Java/Go/Swift: Move CsvValidation back into ExternalFlow.
1 parent d2087ec commit 37976d5

26 files changed

Lines changed: 521 additions & 533 deletions

File tree

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

Lines changed: 0 additions & 140 deletions
This file was deleted.

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

Lines changed: 136 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -315,6 +315,142 @@ predicate modelCoverage(string namespace, int namespaces, string kind, string pa
315315
)
316316
}
317317

318+
/** Provides a query predicate to check the CSV data for validation errors. */
319+
module CsvValidation {
320+
private string getInvalidModelInput() {
321+
exists(string pred, AccessPath input, string part |
322+
sinkModel(_, _, _, _, _, _, input, _, _) and pred = "sink"
323+
or
324+
summaryModel(_, _, _, _, _, _, input, _, _, _) and pred = "summary"
325+
|
326+
(
327+
invalidSpecComponent(input, part) and
328+
not part = "" and
329+
not (part = "Argument" and pred = "sink") and
330+
not parseArg(part, _)
331+
or
332+
part = input.getToken(_) and
333+
parseParam(part, _)
334+
) and
335+
result = "Unrecognized input specification \"" + part + "\" in " + pred + " model."
336+
)
337+
}
338+
339+
private string getInvalidModelOutput() {
340+
exists(string pred, string output, string part |
341+
sourceModel(_, _, _, _, _, _, output, _, _) and pred = "source"
342+
or
343+
summaryModel(_, _, _, _, _, _, _, output, _, _) and pred = "summary"
344+
|
345+
invalidSpecComponent(output, part) and
346+
not part = "" and
347+
not (part = ["Argument", "Parameter"] and pred = "source") and
348+
result = "Unrecognized output specification \"" + part + "\" in " + pred + " model."
349+
)
350+
}
351+
352+
private string getInvalidModelKind() {
353+
exists(string row, string kind | summaryModel(row) |
354+
kind = row.splitAt(";", 8) and
355+
not kind = ["taint", "value"] and
356+
result = "Invalid kind \"" + kind + "\" in summary model."
357+
)
358+
or
359+
exists(string row, string kind | sinkModel(row) |
360+
kind = row.splitAt(";", 7) and
361+
not kind = ["code", "sql", "xss", "remote", "html"] and
362+
result = "Invalid kind \"" + kind + "\" in sink model."
363+
)
364+
or
365+
exists(string row, string kind | sourceModel(row) |
366+
kind = row.splitAt(";", 7) and
367+
not kind = "local" and
368+
result = "Invalid kind \"" + kind + "\" in source model."
369+
)
370+
}
371+
372+
private string getInvalidModelSubtype() {
373+
exists(string pred, string row, int expect |
374+
sourceModel(row) and expect = 9 and pred = "source"
375+
or
376+
sinkModel(row) and expect = 9 and pred = "sink"
377+
or
378+
summaryModel(row) and expect = 10 and pred = "summary"
379+
|
380+
exists(string b |
381+
b = row.splitAt(";", 2) and
382+
not b = ["true", "false"] and
383+
result = "Invalid boolean \"" + b + "\" in " + pred + " model."
384+
)
385+
)
386+
}
387+
388+
private string getInvalidModelColumnCount() {
389+
exists(string pred, string row, int expect |
390+
sourceModel(row) and expect = 9 and pred = "source"
391+
or
392+
sinkModel(row) and expect = 9 and pred = "sink"
393+
or
394+
summaryModel(row) and expect = 10 and pred = "summary"
395+
or
396+
negativeSummaryModel(row) and expect = 5 and pred = "negative summary"
397+
|
398+
exists(int cols |
399+
cols = 1 + max(int n | exists(row.splitAt(";", n))) and
400+
cols != expect and
401+
result =
402+
"Wrong number of columns in " + pred + " model row, expected " + expect + ", got " + cols +
403+
" in " + row + "."
404+
)
405+
)
406+
}
407+
408+
private string getInvalidModelSignature() {
409+
exists(
410+
string pred, string namespace, string type, string name, string signature, string ext,
411+
string provenance
412+
|
413+
sourceModel(namespace, type, _, name, signature, ext, _, _, provenance) and pred = "source"
414+
or
415+
sinkModel(namespace, type, _, name, signature, ext, _, _, provenance) and pred = "sink"
416+
or
417+
summaryModel(namespace, type, _, name, signature, ext, _, _, _, provenance) and
418+
pred = "summary"
419+
or
420+
negativeSummaryModel(namespace, type, name, signature, provenance) and
421+
ext = "" and
422+
pred = "negative summary"
423+
|
424+
not namespace.regexpMatch("[a-zA-Z0-9_\\.]+") and
425+
result = "Dubious namespace \"" + namespace + "\" in " + pred + " model."
426+
or
427+
not type.regexpMatch("[a-zA-Z0-9_<>,\\+]+") and
428+
result = "Dubious type \"" + type + "\" in " + pred + " model."
429+
or
430+
not name.regexpMatch("[a-zA-Z0-9_<>,]*") and
431+
result = "Dubious member name \"" + name + "\" in " + pred + " model."
432+
or
433+
not signature.regexpMatch("|\\([a-zA-Z0-9_<>\\.\\+\\*,\\[\\]]*\\)") and
434+
result = "Dubious signature \"" + signature + "\" in " + pred + " model."
435+
or
436+
not ext.regexpMatch("|Attribute") and
437+
result = "Unrecognized extra API graph element \"" + ext + "\" in " + pred + " model."
438+
or
439+
not provenance = ["manual", "generated"] and
440+
result = "Unrecognized provenance description \"" + provenance + "\" in " + pred + " model."
441+
)
442+
}
443+
444+
/** Holds if some row in a CSV-based flow model appears to contain typos. */
445+
query predicate invalidModelRow(string msg) {
446+
msg =
447+
[
448+
getInvalidModelSignature(), getInvalidModelInput(), getInvalidModelOutput(),
449+
getInvalidModelSubtype(), getInvalidModelColumnCount(), getInvalidModelKind()
450+
]
451+
}
452+
}
453+
318454
private predicate elementSpec(
319455
string namespace, string type, boolean subtypes, string name, string signature, string ext
320456
) {

csharp/ql/test/library-tests/dataflow/external-models/ExternalFlow.expected

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
invalidModelRow
21
edges
32
| ExternalFlow.cs:9:27:9:38 | object creation of type Object : Object | ExternalFlow.cs:10:29:10:32 | access to local variable arg1 : Object |
43
| ExternalFlow.cs:10:29:10:32 | access to local variable arg1 : Object | ExternalFlow.cs:10:18:10:33 | call to method StepArgRes |
@@ -152,6 +151,7 @@ nodes
152151
| ExternalFlow.cs:196:18:196:40 | call to method MixedFlowArgs | semmle.label | call to method MixedFlowArgs |
153152
| ExternalFlow.cs:196:38:196:39 | access to local variable o2 : Object | semmle.label | access to local variable o2 : Object |
154153
subpaths
154+
invalidModelRow
155155
#select
156156
| ExternalFlow.cs:10:18:10:33 | call to method StepArgRes | ExternalFlow.cs:9:27:9:38 | object creation of type Object : Object | ExternalFlow.cs:10:18:10:33 | call to method StepArgRes | $@ | ExternalFlow.cs:9:27:9:38 | object creation of type Object : Object | object creation of type Object : Object |
157157
| ExternalFlow.cs:18:18:18:24 | access to local variable argOut1 | ExternalFlow.cs:15:29:15:40 | object creation of type Object : Object | ExternalFlow.cs:18:18:18:24 | access to local variable argOut1 | $@ | ExternalFlow.cs:15:29:15:40 | object creation of type Object : Object | object creation of type Object : Object |

csharp/ql/test/library-tests/dataflow/external-models/ExternalFlow.ql

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@
44

55
import csharp
66
import DataFlow::PathGraph
7-
import semmle.code.csharp.dataflow.CsvValidation
87
import semmle.code.csharp.dataflow.ExternalFlow
8+
import CsvValidation
99

1010
class SummaryModelTest extends SummaryModelCsv {
1111
override predicate row(string row) {

csharp/ql/test/library-tests/dataflow/external-models/negativesummaries.ql

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,6 @@
33
*/
44

55
import csharp
6-
import semmle.code.csharp.dataflow.CsvValidation
6+
import semmle.code.csharp.dataflow.ExternalFlow
77
import semmle.code.csharp.dataflow.NegativeSummary
8+
import CsvValidation

csharp/ql/test/library-tests/dataflow/external-models/sinks.ql

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
import csharp
22
import DataFlow
3-
import semmle.code.csharp.dataflow.CsvValidation
43
import semmle.code.csharp.dataflow.ExternalFlow
54
import semmle.code.csharp.dataflow.internal.FlowSummaryImpl as FlowSummaryImpl
5+
import CsvValidation
66

77
class SinkModelTest extends SinkModelCsv {
88
override predicate row(string row) {

csharp/ql/test/library-tests/dataflow/external-models/srcs.ql

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
import csharp
22
import DataFlow
3-
import semmle.code.csharp.dataflow.CsvValidation
43
import semmle.code.csharp.dataflow.ExternalFlow
54
import semmle.code.csharp.dataflow.internal.FlowSummaryImpl as FlowSummaryImpl
5+
import CsvValidation
66

77
class SourceModelTest extends SourceModelCsv {
88
override predicate row(string row) {

csharp/ql/test/library-tests/dataflow/external-models/steps.ql

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
import csharp
22
import DataFlow
3-
import semmle.code.csharp.dataflow.CsvValidation
43
import semmle.code.csharp.dataflow.ExternalFlow
54
import semmle.code.csharp.dataflow.FlowSummary
65
import semmle.code.csharp.dataflow.internal.DataFlowDispatch as DataFlowDispatch
76
import semmle.code.csharp.dataflow.internal.FlowSummaryImpl as FlowSummaryImpl
7+
import CsvValidation
88

99
private class SummaryModelTest extends SummaryModelCsv {
1010
override predicate row(string row) {

0 commit comments

Comments
 (0)