Skip to content

Commit d69c622

Browse files
committed
Ruby: Block for steps into self parameters in trackModuleAccess
1 parent d6e7fc4 commit d69c622

2 files changed

Lines changed: 15 additions & 9 deletions

File tree

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

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -537,9 +537,14 @@ private DataFlow::LocalSourceNode trackModuleAccess(Module m, TypeTracker t) {
537537
)
538538
}
539539

540+
/**
541+
* We exclude steps into `self` parameters, and instead rely on the type of the
542+
* enclosing module.
543+
*/
540544
pragma[nomagic]
541545
private DataFlow::LocalSourceNode trackModuleAccessRec(Module m, TypeTracker t, StepSummary summary) {
542-
StepSummary::step(trackModuleAccess(m, t), result, summary)
546+
StepSummary::step(trackModuleAccess(m, t), result, summary) and
547+
not result instanceof SelfParameterNode
543548
}
544549

545550
pragma[nomagic]
@@ -603,17 +608,22 @@ private predicate isInstance(DataFlow::Node n, Module tp, boolean exact) {
603608
or
604609
exists(RelevantCall call, DataFlow::LocalSourceNode sourceNode |
605610
flowsToMethodCallReceiver(call, sourceNode, "new") and
606-
exact = true and
607611
n.asExpr() = call
608612
|
609613
// `C.new`
610-
sourceNode = trackModuleAccess(tp)
614+
sourceNode = trackModuleAccess(tp) and
615+
exact = true
611616
or
612617
// `self.new` inside a module
613-
selfInModule(sourceNode.(SsaSelfDefinitionNode).getVariable(), tp)
618+
selfInModule(sourceNode.(SsaSelfDefinitionNode).getVariable(), tp) and
619+
exact = true
614620
or
615621
// `self.new` inside a singleton method
616-
selfInMethod(sourceNode.(SsaSelfDefinitionNode).getVariable(), any(SingletonMethod sm), tp)
622+
exists(MethodBase target |
623+
selfInMethod(sourceNode.(SsaSelfDefinitionNode).getVariable(), target, tp) and
624+
singletonMethod(target, _, _) and
625+
exact = false
626+
)
617627
)
618628
or
619629
// `self` reference in method or top-level (but not in module or singleton method,

ruby/ql/test/library-tests/modules/callgraph.expected

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -232,11 +232,7 @@ getTarget
232232
| calls.rb:595:9:595:23 | call to call_singleton1 | calls.rb:590:5:592:7 | call_singleton1 |
233233
| calls.rb:595:9:595:23 | call to call_singleton1 | calls.rb:603:5:605:7 | call_singleton1 |
234234
| calls.rb:595:9:595:23 | call to call_singleton1 | calls.rb:612:5:614:7 | call_singleton1 |
235-
| calls.rb:604:9:604:18 | call to singleton1 | calls.rb:587:5:588:7 | singleton1 |
236235
| calls.rb:604:9:604:18 | call to singleton1 | calls.rb:600:5:601:7 | singleton1 |
237-
| calls.rb:604:9:604:18 | call to singleton1 | calls.rb:609:5:610:7 | singleton1 |
238-
| calls.rb:613:9:613:18 | call to singleton1 | calls.rb:587:5:588:7 | singleton1 |
239-
| calls.rb:613:9:613:18 | call to singleton1 | calls.rb:600:5:601:7 | singleton1 |
240236
| calls.rb:613:9:613:18 | call to singleton1 | calls.rb:609:5:610:7 | singleton1 |
241237
| calls.rb:617:1:617:31 | call to call_call_singleton1 | calls.rb:594:5:596:7 | call_call_singleton1 |
242238
| calls.rb:618:1:618:31 | call to call_call_singleton1 | calls.rb:594:5:596:7 | call_call_singleton1 |

0 commit comments

Comments
 (0)