Skip to content

Commit a06a9ff

Browse files
committed
Address review comments
1 parent 6de315d commit a06a9ff

File tree

3 files changed

+26
-27
lines changed

3 files changed

+26
-27
lines changed

ruby/ql/lib/codeql/ruby/controlflow/CfgNodes.qll

+5-1
Original file line numberDiff line numberDiff line change
@@ -201,7 +201,11 @@ module ExprNodes {
201201

202202
override LhsExpr getExpr() { result = super.getExpr() }
203203

204-
/** Gets a variable used in (or introduced by) this LHS. */
204+
/**
205+
* DEPRECATED: use `getVariable` instead.
206+
*
207+
* Gets a variable used in (or introduced by) this LHS.
208+
*/
205209
deprecated Variable getAVariable() { result = e.(VariableAccess).getVariable() }
206210

207211
/** Gets the variable used in (or introduced by) this LHS. */

ruby/ql/lib/codeql/ruby/dataflow/FlowSummary.qll

+16-25
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,7 @@ class RequiredSummaryComponentStack = Impl::Public::RequiredSummaryComponentStac
163163

164164
/**
165165
* Provides a set of special flow summaries to ensure that callbacks passed into
166-
* library methods will be passed as `self` arguments into themeselves. That is,
166+
* library methods will be passed as `lambda-self` arguments into themselves. That is,
167167
* we are assuming that callbacks passed into library methods will be called, which is
168168
* needed for flow through captured variables.
169169
*/
@@ -172,21 +172,6 @@ private module LibraryCallbackSummaries {
172172
not exists(getTarget(call))
173173
}
174174

175-
private class LibraryBlockMethod extends SummarizedCallable {
176-
LibraryBlockMethod() { this = "<library method accepting a block>" }
177-
178-
final override MethodCall getACall() {
179-
libraryCall(result.getAControlFlowNode()) and
180-
result.hasBlock()
181-
}
182-
183-
override predicate propagatesFlowExt(string input, string output, boolean preservesValue) {
184-
input = "Argument[block]" and
185-
output = "Argument[block].Parameter[lambda-self]" and
186-
preservesValue = true
187-
}
188-
}
189-
190175
private DataFlow::LocalSourceNode trackLambdaCreation(TypeTracker t) {
191176
t.start() and
192177
lambdaCreation(result, TLambdaCallKind(), _)
@@ -205,20 +190,26 @@ private module LibraryCallbackSummaries {
205190
}
206191

207192
private class LibraryLambdaMethod extends SummarizedCallable {
208-
private int i;
209-
210-
LibraryLambdaMethod() {
211-
this = "<library method accepting a lambda at index " + i + ">" and
212-
i in [0 .. 10]
213-
}
193+
LibraryLambdaMethod() { this = "<library method accepting a callback>" }
214194

215195
final override MethodCall getACall() {
216-
libraryCallHasLambdaArg(result.getAControlFlowNode(), i)
196+
libraryCall(result.getAControlFlowNode()) and
197+
result.hasBlock()
198+
or
199+
libraryCallHasLambdaArg(result.getAControlFlowNode(), _)
217200
}
218201

219202
override predicate propagatesFlowExt(string input, string output, boolean preservesValue) {
220-
input = "Argument[" + i + "]" and
221-
output = "Argument[" + i + "].Parameter[lambda-self]" and
203+
(
204+
input = "Argument[block]" and
205+
output = "Argument[block].Parameter[lambda-self]"
206+
or
207+
exists(int i |
208+
i in [0 .. 10] and
209+
input = "Argument[" + i + "]" and
210+
output = "Argument[" + i + "].Parameter[lambda-self]"
211+
)
212+
) and
222213
preservesValue = true
223214
}
224215
}

ruby/ql/lib/codeql/ruby/dataflow/internal/DataFlowPublic.qll

+5-1
Original file line numberDiff line numberDiff line change
@@ -1219,7 +1219,11 @@ class LhsExprNode extends ExprNode {
12191219
/** Gets the underlying AST node as a `LhsExpr`. */
12201220
LhsExpr asLhsExprAstNode() { result = lhsExprCfgNode.getExpr() }
12211221

1222-
/** Gets a variable used in (or introduced by) this LHS. */
1222+
/**
1223+
* DEPRECATED: use `getVariable` instead.
1224+
*
1225+
* Gets a variable used in (or introduced by) this LHS.
1226+
*/
12231227
deprecated Variable getAVariable() { result = lhsExprCfgNode.getAVariable() }
12241228

12251229
/** Gets the variable used in (or introduced by) this LHS. */

0 commit comments

Comments
 (0)