Skip to content

Commit 8a8e8fc

Browse files
committed
Ruby: Do not cache getAMaybeGuardedCapturedDef
1 parent 9833d39 commit 8a8e8fc

File tree

2 files changed

+20
-32
lines changed

2 files changed

+20
-32
lines changed

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

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -854,13 +854,21 @@ class ContentSet extends TContentSet {
854854
*/
855855
signature predicate guardChecksSig(CfgNodes::AstCfgNode g, CfgNode e, boolean branch);
856856

857+
bindingset[def1, def2]
858+
pragma[inline_late]
859+
private predicate sameSourceVariable(Ssa::Definition def1, Ssa::Definition def2) {
860+
def1.getSourceVariable() = def2.getSourceVariable()
861+
}
862+
857863
/**
858864
* Provides a set of barrier nodes for a guard that validates an expression.
859865
*
860866
* This is expected to be used in `isBarrier`/`isSanitizer` definitions
861867
* in data flow and taint tracking.
862868
*/
863869
module BarrierGuard<guardChecksSig/3 guardChecks> {
870+
private import codeql.ruby.controlflow.internal.Guards
871+
864872
/**
865873
* Gets an implicit entry definition for a captured variable that
866874
* may be guarded, because a call to the capturing callable is guarded.
@@ -870,9 +878,15 @@ module BarrierGuard<guardChecksSig/3 guardChecks> {
870878
*/
871879
pragma[nomagic]
872880
private Ssa::CapturedEntryDefinition getAMaybeGuardedCapturedDef() {
873-
exists(CfgNodes::ExprCfgNode g, boolean branch, Ssa::Definition def |
874-
result = SsaImpl::getAMaybeGuardedCapturedDef(g, branch, def) and
875-
guardChecks(g, def.getARead(), branch)
881+
exists(
882+
CfgNodes::ExprCfgNode g, boolean branch, CfgNodes::ExprCfgNode testedNode,
883+
Ssa::Definition def, CfgNodes::ExprNodes::CallCfgNode call
884+
|
885+
def.getARead() = testedNode and
886+
guardChecks(g, testedNode, branch) and
887+
guardControlsBlock(g, call.getBasicBlock(), branch) and
888+
result.getBasicBlock().getScope() = call.getExpr().(MethodCall).getBlock() and
889+
sameSourceVariable(def, result)
876890
)
877891
}
878892

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

Lines changed: 3 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -439,30 +439,6 @@ private module Cached {
439439
result = DataFlowIntegrationImpl::getABarrierNode(guard, def, branch)
440440
}
441441
}
442-
443-
bindingset[def1, def2]
444-
pragma[inline_late]
445-
private predicate sameSourceVariable(Ssa::Definition def1, Ssa::Definition def2) {
446-
def1.getSourceVariable() = def2.getSourceVariable()
447-
}
448-
449-
/**
450-
* Gets an implicit entry definition for a captured variable that
451-
* may be guarded, because a call to the capturing callable is guarded.
452-
*
453-
* This is restricted to calls where the variable is captured inside a
454-
* block.
455-
*/
456-
cached
457-
Ssa::CapturedEntryDefinition getAMaybeGuardedCapturedDef(
458-
Cfg::CfgNodes::ExprCfgNode g, boolean branch, Ssa::Definition def
459-
) {
460-
exists(Cfg::CfgNodes::ExprNodes::CallCfgNode call |
461-
DataFlowIntegrationInput::guardControlsBlock(g, call.getBasicBlock(), branch) and
462-
result.getBasicBlock().getScope() = call.getExpr().(MethodCall).getBlock() and
463-
sameSourceVariable(def, result)
464-
)
465-
}
466442
}
467443

468444
import Cached
@@ -552,6 +528,8 @@ class ParameterExt extends TParameterExt {
552528
}
553529

554530
private module DataFlowIntegrationInput implements Impl::DataFlowIntegrationInputSig {
531+
private import codeql.ruby.controlflow.internal.Guards as Guards
532+
555533
class Parameter = ParameterExt;
556534

557535
class Expr extends Cfg::CfgNodes::ExprCfgNode {
@@ -570,11 +548,7 @@ private module DataFlowIntegrationInput implements Impl::DataFlowIntegrationInpu
570548

571549
/** Holds if the guard `guard` controls block `bb` upon evaluating to `branch`. */
572550
predicate guardControlsBlock(Guard guard, SsaInput::BasicBlock bb, boolean branch) {
573-
exists(Cfg::ConditionBlock conditionBlock, Cfg::SuccessorTypes::ConditionalSuccessor s |
574-
guard = conditionBlock.getLastNode() and
575-
s.getValue() = branch and
576-
conditionBlock.controls(bb, s)
577-
)
551+
Guards::guardControlsBlock(guard, bb, branch)
578552
}
579553

580554
/** Gets an immediate conditional successor of basic block `bb`, if any. */

0 commit comments

Comments
 (0)