Skip to content

Commit 9558522

Browse files
authored
Merge pull request github#13070 from michaelnebel/csharp/refactorfollowup
C#: Re-factor CIL data flow test to use the new API.
2 parents 4960305 + 9e990e7 commit 9558522

File tree

2 files changed

+18
-18
lines changed

2 files changed

+18
-18
lines changed

csharp/ql/src/experimental/Security Features/CWE-759/HashWithoutSalt.ql

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,6 @@
1010
*/
1111

1212
import csharp
13-
import semmle.code.csharp.dataflow.DataFlow2
14-
import semmle.code.csharp.dataflow.TaintTracking2
1513
import HashWithoutSalt::PathGraph
1614

1715
/** The C# class `Windows.Security.Cryptography.Core.HashAlgorithmProvider`. */
@@ -77,7 +75,7 @@ predicate isHashCall(MethodCall mc) {
7775

7876
/** Holds if there is another hashing method call. */
7977
predicate hasAnotherHashCall(MethodCall mc) {
80-
exists(MethodCall mc2, DataFlow2::Node src, DataFlow2::Node sink |
78+
exists(MethodCall mc2, DataFlow::Node src, DataFlow::Node sink |
8179
isHashCall(mc2) and
8280
mc2 != mc and
8381
(

csharp/ql/test/library-tests/cil/dataflow/DataFlow.ql

Lines changed: 17 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -3,45 +3,47 @@
33
*/
44

55
import csharp
6-
import DataFlow
6+
import Flow::PathGraph
77

8-
private predicate relevantPathNode(PathNode n) {
8+
private predicate relevantPathNode(Flow::PathNode n) {
99
exists(File f | f = n.getNode().getLocation().getFile() |
1010
f.fromSource()
1111
or
1212
f.getBaseName() = "DataFlow.dll"
1313
)
1414
}
1515

16-
query predicate edges(PathNode a, PathNode b) {
17-
PathGraph::edges(a, b) and
16+
query predicate edges(Flow::PathNode a, Flow::PathNode b) {
17+
Flow::PathGraph::edges(a, b) and
1818
relevantPathNode(a) and
1919
relevantPathNode(b)
2020
}
2121

22-
query predicate nodes(PathNode n, string key, string val) {
23-
PathGraph::nodes(n, key, val) and
22+
query predicate nodes(Flow::PathNode n, string key, string val) {
23+
Flow::PathGraph::nodes(n, key, val) and
2424
relevantPathNode(n)
2525
}
2626

27-
query predicate subpaths(PathNode arg, PathNode par, PathNode ret, PathNode out) {
28-
PathGraph::subpaths(arg, par, ret, out) and
27+
query predicate subpaths(
28+
Flow::PathNode arg, Flow::PathNode par, Flow::PathNode ret, Flow::PathNode out
29+
) {
30+
Flow::PathGraph::subpaths(arg, par, ret, out) and
2931
relevantPathNode(arg) and
3032
relevantPathNode(par) and
3133
relevantPathNode(ret) and
3234
relevantPathNode(out)
3335
}
3436

35-
class FlowConfig extends Configuration {
36-
FlowConfig() { this = "FlowConfig" }
37+
module FlowConfig implements DataFlow::ConfigSig {
38+
predicate isSource(DataFlow::Node source) { source.asExpr() instanceof Literal }
3739

38-
override predicate isSource(Node source) { source.asExpr() instanceof Literal }
39-
40-
override predicate isSink(Node sink) {
40+
predicate isSink(DataFlow::Node sink) {
4141
exists(LocalVariable decl | sink.asExpr() = decl.getInitializer())
4242
}
4343
}
4444

45-
from PathNode source, PathNode sink, FlowConfig config
46-
where config.hasFlowPath(source, sink)
45+
module Flow = DataFlow::Global<FlowConfig>;
46+
47+
from Flow::PathNode source, Flow::PathNode sink
48+
where Flow::flowPath(source, sink)
4749
select source, sink, sink, "$@", sink, sink.toString()

0 commit comments

Comments
 (0)