Skip to content

Commit 6a198ff

Browse files
authored
Merge pull request github#1306 from hvitved/csharp/dataflow/shared-implementation
C#: Adopt shared data flow implementation
2 parents 1076c03 + 949b360 commit 6a198ff

File tree

64 files changed

+10108
-4532
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

64 files changed

+10108
-4532
lines changed

config/identical-files.json

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,14 @@
1313
"cpp/ql/src/semmle/code/cpp/ir/dataflow/internal/DataFlowImpl.qll",
1414
"cpp/ql/src/semmle/code/cpp/ir/dataflow/internal/DataFlowImpl2.qll",
1515
"cpp/ql/src/semmle/code/cpp/ir/dataflow/internal/DataFlowImpl3.qll",
16-
"cpp/ql/src/semmle/code/cpp/ir/dataflow/internal/DataFlowImpl4.qll"
16+
"cpp/ql/src/semmle/code/cpp/ir/dataflow/internal/DataFlowImpl4.qll",
17+
"csharp/ql/src/semmle/code/csharp/dataflow/internal/DataFlowImpl.qll"
1718
],
1819
"DataFlow Java/C++ Common": [
1920
"java/ql/src/semmle/code/java/dataflow/internal/DataFlowImplCommon.qll",
2021
"cpp/ql/src/semmle/code/cpp/dataflow/internal/DataFlowImplCommon.qll",
21-
"cpp/ql/src/semmle/code/cpp/ir/dataflow/internal/DataFlowImplCommon.qll"
22+
"cpp/ql/src/semmle/code/cpp/ir/dataflow/internal/DataFlowImplCommon.qll",
23+
"csharp/ql/src/semmle/code/csharp/dataflow/internal/DataFlowImplCommon.qll"
2224
],
2325
"C++ IR Instruction": [
2426
"cpp/ql/src/semmle/code/cpp/ir/implementation/raw/Instruction.qll",

csharp/ql/src/Security Features/CWE-798/HardcodedCredentials.ql

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ from
2121
where
2222
source = sourcePath.getNode() and
2323
sink = sinkPath.getNode() and
24-
c.hasFlow(source, sink) and
24+
c.hasFlowPath(sourcePath, sinkPath) and
2525
// Print the source value if it's available
2626
if exists(source.asExpr().getValue())
2727
then value = "The hard-coded value \"" + source.asExpr().getValue() + "\""

csharp/ql/src/semmle/code/csharp/dataflow/CallContext.qll

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

55
import csharp
6-
private import semmle.code.csharp.dataflow.DelegateDataFlow
7-
private import dotnet
6+
private import semmle.code.csharp.dataflow.internal.DelegateDataFlow
7+
private import semmle.code.csharp.dispatch.Dispatch
88

99
// Internal representation of call contexts
1010
cached
1111
private newtype TCallContext =
1212
TEmptyCallContext() or
13-
TArgCallContext(DotNet::Call c, int i) { exists(c.getArgument(i)) } or
14-
TDynamicAccessorArgCallContext(DynamicAccessorCall dac, int i) { exists(dac.getArgument(i)) } or
13+
TArgNonDelegateCallContext(Expr arg) { exists(DispatchCall dc | arg = dc.getArgument(_)) } or
14+
TArgDelegateCallContext(DelegateCall dc, int i) { exists(dc.getArgument(i)) } or
1515
TDelegateToLibraryCallableArgCallContext(DelegateArgumentToLibraryCallable arg, int i) {
1616
exists(arg.getDelegateType().getParameter(i))
1717
}
@@ -32,6 +32,8 @@ class CallContext extends TCallContext {
3232
/** An empty call context. */
3333
class EmptyCallContext extends CallContext, TEmptyCallContext {
3434
override string toString() { result = "<empty>" }
35+
36+
override EmptyLocation getLocation() { any() }
3537
}
3638

3739
/**
@@ -43,43 +45,40 @@ abstract class ArgumentCallContext extends CallContext {
4345
* Holds if this call context represents the argument at position `i` of the
4446
* call expression `call`.
4547
*/
46-
abstract predicate isArgument(DotNet::Expr call, int i);
48+
abstract predicate isArgument(Expr call, int i);
4749
}
4850

49-
/** An argument of an ordinary call. */
50-
class CallArgumentCallContext extends ArgumentCallContext, TArgCallContext {
51-
DotNet::Call c;
52-
53-
int arg;
51+
/** An argument of a non-delegate call. */
52+
class NonDelegateCallArgumentCallContext extends ArgumentCallContext, TArgNonDelegateCallContext {
53+
Expr arg;
5454

55-
CallArgumentCallContext() { this = TArgCallContext(c, arg) }
55+
NonDelegateCallArgumentCallContext() { this = TArgNonDelegateCallContext(arg) }
5656

57-
override predicate isArgument(DotNet::Expr call, int i) {
58-
call = c and
59-
i = arg
57+
override predicate isArgument(Expr call, int i) {
58+
exists(DispatchCall dc | arg = dc.getArgument(i) | call = dc.getCall())
6059
}
6160

62-
override string toString() { result = c.getArgument(arg).toString() }
61+
override string toString() { result = arg.toString() }
6362

64-
override Location getLocation() { result = c.getArgument(arg).getLocation() }
63+
override Location getLocation() { result = arg.getLocation() }
6564
}
6665

67-
/** An argument of a dynamic accessor call. */
68-
class DynamicAccessorArgumentCallContext extends ArgumentCallContext, TDynamicAccessorArgCallContext {
69-
DynamicAccessorCall dac;
66+
/** An argument of a delegate call. */
67+
class DelegateCallArgumentCallContext extends ArgumentCallContext, TArgDelegateCallContext {
68+
DelegateCall dc;
7069

7170
int arg;
7271

73-
DynamicAccessorArgumentCallContext() { this = TDynamicAccessorArgCallContext(dac, arg) }
72+
DelegateCallArgumentCallContext() { this = TArgDelegateCallContext(dc, arg) }
7473

75-
override predicate isArgument(DotNet::Expr call, int i) {
76-
call = dac and
74+
override predicate isArgument(Expr call, int i) {
75+
call = dc and
7776
i = arg
7877
}
7978

80-
override string toString() { result = dac.getArgument(arg).toString() }
79+
override string toString() { result = dc.getArgument(arg).toString() }
8180

82-
override Location getLocation() { result = dac.getArgument(arg).getLocation() }
81+
override Location getLocation() { result = dc.getArgument(arg).getLocation() }
8382
}
8483

8584
/**
@@ -93,15 +92,15 @@ class DynamicAccessorArgumentCallContext extends ArgumentCallContext, TDynamicAc
9392
*/
9493
class DelegateArgumentToLibraryCallableArgumentContext extends ArgumentCallContext,
9594
TDelegateToLibraryCallableArgCallContext {
96-
DotNet::Expr delegate;
95+
Expr delegate;
9796

9897
int arg;
9998

10099
DelegateArgumentToLibraryCallableArgumentContext() {
101100
this = TDelegateToLibraryCallableArgCallContext(delegate, arg)
102101
}
103102

104-
override predicate isArgument(DotNet::Expr call, int i) {
103+
override predicate isArgument(Expr call, int i) {
105104
call = delegate and
106105
i = arg
107106
}

0 commit comments

Comments
 (0)