Skip to content

Commit 5d55daa

Browse files
committed
Ruby: use resolveConstantReadAccess instead of trackModuleAccess for 'extend' calls
This avoids non-linear recursion at the cost of losing some results.
1 parent c2b98a4 commit 5d55daa

File tree

1 file changed

+7
-5
lines changed

1 file changed

+7
-5
lines changed

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

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -295,22 +295,24 @@ private DataFlowCallable viableLibraryCallable(DataFlowCall call) {
295295
}
296296

297297
/** Holds if there is a call like `receiver.extend(M)` */
298-
private predicate extendCall(DataFlow::LocalSourceNode receiver, Module m) {
298+
pragma[nomagic]
299+
private predicate flowsToExtendCall(DataFlow::LocalSourceNode receiver, Module m) {
299300
exists(DataFlow::CallNode extendCall |
300301
extendCall.getMethodName() = "extend" and
301302
exists(DataFlow::LocalSourceNode sourceNode | sourceNode.flowsTo(extendCall.getArgument(0)) |
302303
selfInModule(sourceNode.(SsaSelfDefinitionNode).getVariable(), m) or
303-
sourceNode = trackModuleAccess(m)
304+
m = resolveConstantReadAccess(sourceNode.asExpr().getExpr())
304305
) and
305306
receiver.flowsTo(extendCall.getReceiver())
306307
)
307308
}
308309

309310
/** Holds if there is a call like `M.extend(N)` */
311+
pragma[nomagic]
310312
private predicate extendCallModule(Module m, Module n) {
311-
exists(DataFlow::LocalSourceNode receiver | extendCall(receiver, n) |
313+
exists(DataFlow::LocalSourceNode receiver | flowsToExtendCall(receiver, n) |
312314
selfInModule(receiver.(SsaSelfDefinitionNode).getVariable(), m) or
313-
receiver = trackModuleAccess(m)
315+
m = resolveConstantReadAccess(receiver.asExpr().getExpr())
314316
)
315317
}
316318

@@ -375,7 +377,7 @@ private module Cached {
375377
receiver = trackSingletonMethodOnInstance(result, method)
376378
or
377379
exists(Module m |
378-
extendCall(any(DataFlow::LocalSourceNode n | n.flowsTo(receiver)), m) and
380+
flowsToExtendCall(any(DataFlow::LocalSourceNode n | n.flowsTo(receiver)), m) and
379381
result = lookupMethod(m, pragma[only_bind_into](method))
380382
)
381383
)

0 commit comments

Comments
 (0)