Skip to content

Commit c6a471e

Browse files
committed
C#: Adopt shared data flow implementation
- General refactoring to fit with the shared data flow implementation. - Move CFG splitting logic into `ControlFlowReachability.qll`. - Replace `isAdditionalFlowStepIntoCall()` with `TaintedParameterNode`. - Redefine `ReturnNode` to be the actual values that are returned, which should yield better path information. - No longer consider overrides in CIL calls.
1 parent a6fa6df commit c6a471e

File tree

56 files changed

+7870
-4416
lines changed

Some content is hidden

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

56 files changed

+7870
-4416
lines changed

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

Lines changed: 19 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,15 @@
44

55
import csharp
66
private import semmle.code.csharp.dataflow.DelegateDataFlow
7+
private import semmle.code.csharp.dispatch.Dispatch
78
private import dotnet
89

910
// Internal representation of call contexts
1011
cached
1112
private newtype TCallContext =
1213
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
14+
TArgNonDelegateCallContext(DispatchCall dc, int i) { exists(dc.getArgument(i)) } or
15+
TArgDelegateCallContext(DelegateCall dc, int i) { exists(dc.getArgument(i)) } or
1516
TDelegateToLibraryCallableArgCallContext(DelegateArgumentToLibraryCallable arg, int i) {
1617
exists(arg.getDelegateType().getParameter(i))
1718
}
@@ -32,6 +33,8 @@ class CallContext extends TCallContext {
3233
/** An empty call context. */
3334
class EmptyCallContext extends CallContext, TEmptyCallContext {
3435
override string toString() { result = "<empty>" }
36+
37+
override Location getLocation() { result instanceof EmptyLocation }
3538
}
3639

3740
/**
@@ -46,40 +49,40 @@ abstract class ArgumentCallContext extends CallContext {
4649
abstract predicate isArgument(DotNet::Expr call, int i);
4750
}
4851

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

5356
int arg;
5457

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

5760
override predicate isArgument(DotNet::Expr call, int i) {
58-
call = c and
61+
call = dc.getCall() and
5962
i = arg
6063
}
6164

62-
override string toString() { result = c.getArgument(arg).toString() }
65+
override string toString() { result = dc.getArgument(arg).toString() }
6366

64-
override Location getLocation() { result = c.getArgument(arg).getLocation() }
67+
override Location getLocation() { result = dc.getArgument(arg).getLocation() }
6568
}
6669

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

7174
int arg;
7275

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

7578
override predicate isArgument(DotNet::Expr call, int i) {
76-
call = dac and
79+
call = dc and
7780
i = arg
7881
}
7982

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

82-
override Location getLocation() { result = dac.getArgument(arg).getLocation() }
85+
override Location getLocation() { result = dc.getArgument(arg).getLocation() }
8386
}
8487

8588
/**

0 commit comments

Comments
 (0)