Skip to content

Commit 5c8367a

Browse files
committed
C#: Use data flow consistency checks from shared pack
1 parent c4b626a commit 5c8367a

File tree

3 files changed

+19
-318
lines changed

3 files changed

+19
-318
lines changed

config/identical-files.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,6 @@
5959
"java/ql/lib/semmle/code/java/dataflow/internal/DataFlowImplConsistency.qll",
6060
"cpp/ql/lib/semmle/code/cpp/dataflow/internal/DataFlowImplConsistency.qll",
6161
"cpp/ql/lib/semmle/code/cpp/ir/dataflow/internal/DataFlowImplConsistency.qll",
62-
"csharp/ql/lib/semmle/code/csharp/dataflow/internal/DataFlowImplConsistency.qll",
6362
"python/ql/lib/semmle/python/dataflow/new/internal/DataFlowImplConsistency.qll",
6463
"swift/ql/lib/codeql/swift/dataflow/internal/DataFlowImplConsistency.qll"
6564
],
Lines changed: 19 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
11
import csharp
22
import cil
3-
import semmle.code.csharp.dataflow.internal.DataFlowPrivate
4-
import semmle.code.csharp.dataflow.internal.DataFlowPublic
5-
import semmle.code.csharp.dataflow.internal.DataFlowDispatch
6-
import semmle.code.csharp.dataflow.internal.DataFlowImplConsistency::Consistency
3+
private import semmle.code.csharp.dataflow.internal.DataFlowImplSpecific
4+
private import semmle.code.csharp.dataflow.internal.TaintTrackingImplSpecific
5+
private import codeql.dataflow.internal.DataFlowImplConsistency
76

8-
private class MyConsistencyConfiguration extends ConsistencyConfiguration {
9-
override predicate uniqueEnclosingCallableExclude(Node n) {
7+
private module Input implements InputSig<CsharpDataFlow> {
8+
private import CsharpDataFlow
9+
10+
predicate uniqueEnclosingCallableExclude(Node n) {
1011
// TODO: Remove once static initializers are folded into the
1112
// static constructors
1213
exists(ControlFlow::Node cfn |
@@ -15,7 +16,7 @@ private class MyConsistencyConfiguration extends ConsistencyConfiguration {
1516
)
1617
}
1718

18-
override predicate uniqueCallEnclosingCallableExclude(DataFlowCall call) {
19+
predicate uniqueCallEnclosingCallableExclude(DataFlowCall call) {
1920
// TODO: Remove once static initializers are folded into the
2021
// static constructors
2122
exists(ControlFlow::Node cfn |
@@ -24,25 +25,25 @@ private class MyConsistencyConfiguration extends ConsistencyConfiguration {
2425
)
2526
}
2627

27-
override predicate uniqueNodeLocationExclude(Node n) {
28+
predicate uniqueNodeLocationExclude(Node n) {
2829
// Methods with multiple implementations
2930
n instanceof ParameterNode
3031
or
31-
this.missingLocationExclude(n)
32+
missingLocationExclude(n)
3233
}
3334

34-
override predicate missingLocationExclude(Node n) {
35+
predicate missingLocationExclude(Node n) {
3536
// Some CIL methods are missing locations
3637
n.asParameter() instanceof CIL::Parameter
3738
}
3839

39-
override predicate postWithInFlowExclude(Node n) {
40+
predicate postWithInFlowExclude(Node n) {
4041
n instanceof FlowSummaryNode
4142
or
4243
n.asExpr().(ObjectCreation).hasInitializer()
4344
}
4445

45-
override predicate argHasPostUpdateExclude(ArgumentNode n) {
46+
predicate argHasPostUpdateExclude(ArgumentNode n) {
4647
n instanceof FlowSummaryNode
4748
or
4849
not exists(LocalFlow::getAPostUpdateNodeForArg(n.getControlFlowNode()))
@@ -54,28 +55,28 @@ private class MyConsistencyConfiguration extends ConsistencyConfiguration {
5455
n.asExpr() instanceof CIL::Expr
5556
}
5657

57-
override predicate postHasUniquePreExclude(PostUpdateNode n) {
58+
predicate postHasUniquePreExclude(PostUpdateNode n) {
5859
exists(ControlFlow::Nodes::ExprNode e, ControlFlow::Nodes::ExprNode arg |
5960
e = LocalFlow::getAPostUpdateNodeForArg(arg) and
6061
e != arg and
6162
n = TExprPostUpdateNode(e)
6263
)
6364
}
6465

65-
override predicate uniquePostUpdateExclude(Node n) {
66+
predicate uniquePostUpdateExclude(Node n) {
6667
exists(ControlFlow::Nodes::ExprNode e, ControlFlow::Nodes::ExprNode arg |
6768
e = LocalFlow::getAPostUpdateNodeForArg(arg) and
6869
e != arg and
6970
n.asExpr() = arg.getExpr()
7071
)
7172
}
7273

73-
override predicate reverseReadExclude(Node n) { n.asExpr() = any(AwaitExpr ae).getExpr() }
74-
75-
override predicate identityLocalStepExclude(Node n) { none() }
74+
predicate reverseReadExclude(Node n) { n.asExpr() = any(AwaitExpr ae).getExpr() }
7675
}
7776

78-
query predicate multipleToString(Node n, string s) {
77+
import MakeConsistency<CsharpDataFlow, CsharpTaintTracking, Input>
78+
79+
query predicate multipleToString(DataFlow::Node n, string s) {
7980
s = strictconcat(n.toString(), ",") and
8081
strictcount(n.toString()) > 1
8182
}

0 commit comments

Comments
 (0)