Skip to content

Commit b3cb250

Browse files
authored
Merge pull request #7516 from michaelnebel/csharp/improve-csv-validation
C#: Introduce Csv validation on kind.
2 parents 9cafab1 + 6fb112f commit b3cb250

File tree

5 files changed

+58
-45
lines changed

5 files changed

+58
-45
lines changed

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

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -349,6 +349,24 @@ module CsvValidation {
349349
msg = "Invalid boolean \"" + b + "\" in " + pred + " model."
350350
)
351351
)
352+
or
353+
exists(string row, string kind | summaryModel(row) |
354+
kind = row.splitAt(";", 8) and
355+
not kind = ["taint", "value"] and
356+
msg = "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+
msg = "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+
msg = "Invalid kind \"" + kind + "\" in source model."
369+
)
352370
}
353371
}
354372

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
invalidModelRow
22
#select
3-
| Sinks.cs:8:19:8:22 | access to local variable arg1 | qltest |
4-
| Sinks.cs:11:13:11:41 | this access | qltest-arg |
5-
| Sinks.cs:11:30:11:40 | access to local variable argToTagged | qltest-arg |
6-
| Sinks.cs:14:27:14:36 | access to local variable fieldWrite | qltest-nospec |
7-
| Sinks.cs:20:20:20:22 | access to local variable res | qltest |
8-
| Sinks.cs:27:20:27:25 | access to local variable resTag | qltest-retval |
3+
| Sinks.cs:8:19:8:22 | access to local variable arg1 | code |
4+
| Sinks.cs:11:13:11:41 | this access | remote |
5+
| Sinks.cs:11:30:11:40 | access to local variable argToTagged | remote |
6+
| Sinks.cs:14:27:14:36 | access to local variable fieldWrite | sql |
7+
| Sinks.cs:20:20:20:22 | access to local variable res | xss |
8+
| Sinks.cs:27:20:27:25 | access to local variable resTag | html |

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

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,11 @@ class SinkModelTest extends SinkModelCsv {
99
row =
1010
[
1111
//"namespace;type;overrides;name;signature;ext;spec;kind",
12-
"My.Qltest;B;false;Sink1;(System.Object);;Argument[0];qltest",
13-
"My.Qltest;B;false;SinkMethod;();;ReturnValue;qltest",
14-
"My.Qltest;SinkAttribute;false;;;Attribute;ReturnValue;qltest-retval",
15-
"My.Qltest;SinkAttribute;false;;;Attribute;Argument;qltest-arg",
16-
"My.Qltest;SinkAttribute;false;;;Attribute;;qltest-nospec"
12+
"My.Qltest;B;false;Sink1;(System.Object);;Argument[0];code",
13+
"My.Qltest;B;false;SinkMethod;();;ReturnValue;xss",
14+
"My.Qltest;SinkAttribute;false;;;Attribute;ReturnValue;html",
15+
"My.Qltest;SinkAttribute;false;;;Attribute;Argument;remote",
16+
"My.Qltest;SinkAttribute;false;;;Attribute;;sql"
1717
]
1818
}
1919
}
Lines changed: 15 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,17 @@
11
invalidModelRow
22
#select
3-
| Sources.cs:8:17:8:22 | call to method Src1 | qltest |
4-
| Sources.cs:8:17:8:22 | call to method Src1 | qltest-all-overloads |
5-
| Sources.cs:9:17:9:24 | call to method Src1 | qltest |
6-
| Sources.cs:9:17:9:24 | call to method Src1 | qltest-all-overloads |
7-
| Sources.cs:12:17:12:26 | call to method Src2 | qltest |
8-
| Sources.cs:12:17:12:26 | call to method Src2 | qltest-w-subtypes |
9-
| Sources.cs:13:17:13:26 | call to method Src3 | qltest-w-subtypes |
10-
| Sources.cs:15:13:15:21 | [post] this access | qltest-argany |
11-
| Sources.cs:15:20:15:20 | [post] access to local variable x | qltest-argany |
12-
| Sources.cs:15:20:15:20 | [post] access to local variable x | qltest-argnum |
13-
| Sources.cs:17:17:17:33 | call to method TaggedSrcMethod | qltest-retval |
14-
| Sources.cs:18:17:18:30 | access to field TaggedSrcField | qltest-nospec |
15-
| Sources.cs:20:17:20:33 | call to method SrcTwoArg | qltest |
16-
| Sources.cs:24:14:24:20 | this | qltest-param |
17-
| Sources.cs:24:29:24:45 | taggedMethodParam | qltest-param |
18-
| Sources.cs:28:49:28:62 | taggedSrcParam | qltest-nospec |
19-
| Sources.cs:28:49:28:62 | taggedSrcParam | qltest-param |
20-
| Sources.cs:40:45:40:45 | p | qltest-param-override |
21-
| Sources.cs:47:50:47:50 | p | qltest-param-override |
22-
| Sources.cs:53:16:53:30 | this | qltest-param |
3+
| Sources.cs:8:17:8:22 | call to method Src1 | local |
4+
| Sources.cs:9:17:9:24 | call to method Src1 | local |
5+
| Sources.cs:12:17:12:26 | call to method Src2 | local |
6+
| Sources.cs:13:17:13:26 | call to method Src3 | local |
7+
| Sources.cs:15:13:15:21 | [post] this access | local |
8+
| Sources.cs:15:20:15:20 | [post] access to local variable x | local |
9+
| Sources.cs:17:17:17:33 | call to method TaggedSrcMethod | local |
10+
| Sources.cs:18:17:18:30 | access to field TaggedSrcField | local |
11+
| Sources.cs:20:17:20:33 | call to method SrcTwoArg | local |
12+
| Sources.cs:24:14:24:20 | this | local |
13+
| Sources.cs:24:29:24:45 | taggedMethodParam | local |
14+
| Sources.cs:28:49:28:62 | taggedSrcParam | local |
15+
| Sources.cs:40:45:40:45 | p | local |
16+
| Sources.cs:47:50:47:50 | p | local |
17+
| Sources.cs:53:16:53:30 | this | local |

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

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -9,20 +9,20 @@ class SourceModelTest extends SourceModelCsv {
99
row =
1010
[
1111
//"namespace;type;overrides;name;signature;ext;spec;kind",
12-
"My.Qltest;A;false;Src1;();;ReturnValue;qltest",
13-
"My.Qltest;A;false;Src1;(System.String);;ReturnValue;qltest",
14-
"My.Qltest;A;false;Src1;;;ReturnValue;qltest-all-overloads",
15-
"My.Qltest;A;false;Src2;();;ReturnValue;qltest",
16-
"My.Qltest;A;false;Src3;();;ReturnValue;qltest",
17-
"My.Qltest;A;true;Src2;();;ReturnValue;qltest-w-subtypes",
18-
"My.Qltest;A;true;Src3;();;ReturnValue;qltest-w-subtypes",
19-
"My.Qltest;A;false;SrcArg;(System.Object);;Argument[0];qltest-argnum",
20-
"My.Qltest;A;false;SrcArg;(System.Object);;Argument;qltest-argany",
21-
"My.Qltest;A;true;SrcParam;(System.Object);;Parameter[0];qltest-param-override",
22-
"My.Qltest;SourceAttribute;false;;;Attribute;ReturnValue;qltest-retval",
23-
"My.Qltest;SourceAttribute;false;;;Attribute;Parameter;qltest-param",
24-
"My.Qltest;SourceAttribute;false;;;Attribute;;qltest-nospec",
25-
"My.Qltest;A;false;SrcTwoArg;(System.String,System.String);;ReturnValue;qltest"
12+
"My.Qltest;A;false;Src1;();;ReturnValue;local",
13+
"My.Qltest;A;false;Src1;(System.String);;ReturnValue;local",
14+
"My.Qltest;A;false;Src1;;;ReturnValue;local",
15+
"My.Qltest;A;false;Src2;();;ReturnValue;local",
16+
"My.Qltest;A;false;Src3;();;ReturnValue;local",
17+
"My.Qltest;A;true;Src2;();;ReturnValue;local",
18+
"My.Qltest;A;true;Src3;();;ReturnValue;local",
19+
"My.Qltest;A;false;SrcArg;(System.Object);;Argument[0];local",
20+
"My.Qltest;A;false;SrcArg;(System.Object);;Argument;local",
21+
"My.Qltest;A;true;SrcParam;(System.Object);;Parameter[0];local",
22+
"My.Qltest;SourceAttribute;false;;;Attribute;ReturnValue;local",
23+
"My.Qltest;SourceAttribute;false;;;Attribute;Parameter;local",
24+
"My.Qltest;SourceAttribute;false;;;Attribute;;local",
25+
"My.Qltest;A;false;SrcTwoArg;(System.String,System.String);;ReturnValue;local"
2626
]
2727
}
2828
}

0 commit comments

Comments
 (0)