Skip to content

Commit 32b4192

Browse files
committed
C#: Address review comments
1 parent 1959480 commit 32b4192

File tree

5 files changed

+30
-22
lines changed

5 files changed

+30
-22
lines changed

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

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,7 @@ class CallableFlowSink extends TCallableFlowSink {
163163
Expr getSink(Call c) { none() }
164164

165165
/**
166-
* Gets the type of the sink for call `c`. Unlik `getSink()`, this is defined
166+
* Gets the type of the sink for call `c`. Unlike `getSink()`, this is defined
167167
* for all flow sink specifications.
168168
*/
169169
Type getSinkType(Call c) { result = this.getSink(c).getType() }
@@ -235,18 +235,22 @@ private CallableFlowSinkDelegateArg getDelegateFlowSinkArg(
235235

236236
/** A flow sink specification: parameter of a delegate argument. */
237237
class CallableFlowSinkDelegateArg extends CallableFlowSink, TCallableFlowSinkDelegateArg {
238-
private int i;
239-
private int j;
238+
private int delegateIndex;
239+
private int parameterIndex;
240240

241-
CallableFlowSinkDelegateArg() { this = TCallableFlowSinkDelegateArg(i, j) }
241+
CallableFlowSinkDelegateArg() {
242+
this = TCallableFlowSinkDelegateArg(delegateIndex, parameterIndex)
243+
}
242244

243245
/** Gets the index of the delegate argument. */
244-
int getDelegateIndex() { result = i }
246+
int getDelegateIndex() { result = delegateIndex }
245247

246248
/** Gets the index of the delegate parameter. */
247-
int getDelegateParameterIndex() { result = j }
249+
int getDelegateParameterIndex() { result = parameterIndex }
248250

249-
override string toString() { result = "parameter " + j + " of argument " + i }
251+
override string toString() {
252+
result = "parameter " + parameterIndex + " of argument " + delegateIndex
253+
}
250254

251255
override Expr getSink(Call c) {
252256
// The uses of the `j`th parameter are the actual sinks
@@ -256,10 +260,10 @@ class CallableFlowSinkDelegateArg extends CallableFlowSink, TCallableFlowSinkDel
256260
override Type getSinkType(Call c) {
257261
result =
258262
c
259-
.getArgument(i)
263+
.getArgument(delegateIndex)
260264
.(DelegateArgumentToLibraryCallable)
261265
.getDelegateType()
262-
.getParameter(j)
266+
.getParameter(parameterIndex)
263267
.getType()
264268
}
265269
}

csharp/ql/src/semmle/code/csharp/dataflow/internal/DataFlowPrivate.qll

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -860,25 +860,29 @@ private module ArgumentNodes {
860860
*/
861861
class ImplicitDelegateArgumentNode extends ArgumentNode, TImplicitDelegateArgumentNode {
862862
private ControlFlow::Node cfn;
863-
private int i;
864-
private int j;
863+
private int delegateIndex;
864+
private int parameterIndex;
865865

866-
ImplicitDelegateArgumentNode() { this = TImplicitDelegateArgumentNode(cfn, i, j) }
866+
ImplicitDelegateArgumentNode() {
867+
this = TImplicitDelegateArgumentNode(cfn, delegateIndex, parameterIndex)
868+
}
867869

868870
private ImplicitDelegateDataFlowCall getDelegateCall() { result.getControlFlowNode() = cfn }
869871

870872
override predicate argumentOf(DataFlowCall call, int pos) {
871873
call = this.getDelegateCall() and
872-
pos = j
874+
pos = parameterIndex
873875
}
874876

875877
override Callable getEnclosingCallable() { result = cfn.getEnclosingCallable() }
876878

877-
override Type getType() { result = this.getDelegateCall().getDelegateParameterType(j) }
879+
override Type getType() {
880+
result = this.getDelegateCall().getDelegateParameterType(parameterIndex)
881+
}
878882

879883
override Location getLocation() { result = cfn.getLocation() }
880884

881-
override string toString() { result = "[implicit argument " + j + "] " + cfn }
885+
override string toString() { result = "[implicit argument " + parameterIndex + "] " + cfn }
882886
}
883887
}
884888

@@ -1332,8 +1336,8 @@ class LibraryCodeNode extends Node, TLibraryCodeNode {
13321336
predicate preservesValue() { preservesValue = true }
13331337

13341338
/**
1335-
* Gets the predecessor of this library-code node. `ap` describes the content
1336-
* that is read from when entering this node (if any).
1339+
* Gets the predecessor of this library-code node. The head of `ap` describes
1340+
* the content that is read from when entering this node (if any).
13371341
*/
13381342
Node getPredecessor(AccessPath ap) {
13391343
ap = sourceAp and
@@ -1352,8 +1356,8 @@ class LibraryCodeNode extends Node, TLibraryCodeNode {
13521356
}
13531357

13541358
/**
1355-
* Gets the successor of this library-code node. `ap` describes the content that
1356-
* is stored into when leaving this node (if any).
1359+
* Gets the successor of this library-code node. The head of `ap` describes
1360+
* the content that is stored into when leaving this node (if any).
13571361
*/
13581362
Node getSuccessor(AccessPath ap) {
13591363
ap = sinkAp and

csharp/ql/src/semmle/code/csharp/dataflow/internal/DelegateDataFlow.qll

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ library class DelegateArgumentToLibraryCallable extends Expr {
119119
Call getCall() { result = call }
120120

121121
/** Gets the index of this delegate argument in the call. */
122-
int getArgumentIndex() { this.getCall().getArgument(result) = this }
122+
int getArgumentIndex() { this = this.getCall().getArgument(result) }
123123

124124
/** Gets the delegate type of this argument. */
125125
DelegateType getDelegateType() { result = dt }

csharp/ql/test/library-tests/dataflow/library/LibraryTypeDataFlow.expected

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1683,7 +1683,7 @@ callableFlow
16831683
| System.Web.HttpUtility.HtmlEncode(string) | argument 0 -> return | false |
16841684
| System.Web.HttpUtility.UrlEncode(string) | argument 0 -> return | false |
16851685
| System.Web.UI.WebControls.TextBox.get_Text() | qualifier -> return | false |
1686-
callableFlowAp
1686+
callableFlowAccessPath
16871687
| System.Lazy<>.Lazy(Func<T>) | output from argument 0 [<empty>] -> return [Value] |
16881688
| System.Lazy<>.Lazy(Func<T>, LazyThreadSafetyMode) | output from argument 0 [<empty>] -> return [Value] |
16891689
| System.Lazy<>.Lazy(Func<T>, bool) | output from argument 0 [<empty>] -> return [Value] |

csharp/ql/test/library-tests/dataflow/library/LibraryTypeDataFlow.ql

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ query predicate callableFlow(string callable, string flow, boolean preservesValu
1313
)
1414
}
1515

16-
query predicate callableFlowAp(string callable, string flow) {
16+
query predicate callableFlowAccessPath(string callable, string flow) {
1717
exists(
1818
LibraryTypeDataFlow x, CallableFlowSource source, AccessPath sourceAp, CallableFlowSink sink,
1919
AccessPath sinkAp, Callable c

0 commit comments

Comments
 (0)