From c2306e6713115f1126ba7b39155d290780422fe7 Mon Sep 17 00:00:00 2001 From: Tom Hvitved Date: Thu, 21 Sep 2023 14:31:25 +0200 Subject: [PATCH] Ruby: Collapse DIL stages --- .../codeql/ruby/dataflow/internal/DataFlowPrivate.qll | 9 ++++++--- .../ruby/dataflow/internal/TaintTrackingPrivate.qll | 3 ++- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/ruby/ql/lib/codeql/ruby/dataflow/internal/DataFlowPrivate.qll b/ruby/ql/lib/codeql/ruby/dataflow/internal/DataFlowPrivate.qll index f53fb80fcea7..b22cf3037d8c 100644 --- a/ruby/ql/lib/codeql/ruby/dataflow/internal/DataFlowPrivate.qll +++ b/ruby/ql/lib/codeql/ruby/dataflow/internal/DataFlowPrivate.qll @@ -282,6 +282,7 @@ module VariableCapture { private import ruby as R private import codeql.ruby.controlflow.ControlFlowGraph private import codeql.ruby.controlflow.BasicBlocks as BasicBlocks + private import TaintTrackingPrivate as TaintTrackingPrivate class Location = R::Location; @@ -296,7 +297,10 @@ module VariableCapture { BasicBlock getABasicBlockSuccessor(BasicBlock bb) { result = bb.getASuccessor() } class CapturedVariable extends LocalVariable { - CapturedVariable() { this.isCaptured() } + CapturedVariable() { + this.isCaptured() and + TaintTrackingPrivate::forceCachingInSameStage() + } Callable getCallable() { exists(Scope scope | scope = this.getDeclaringScope() | @@ -426,12 +430,11 @@ module VariableCapture { /** A collection of cached types and predicates to be evaluated in the same stage. */ cached private module Cached { - private import TaintTrackingPrivate as TaintTrackingPrivate private import codeql.ruby.typetracking.TypeTrackerSpecific as TypeTrackerSpecific cached newtype TNode = - TExprNode(CfgNodes::ExprCfgNode n) { TaintTrackingPrivate::forceCachingInSameStage() } or + TExprNode(CfgNodes::ExprCfgNode n) or TReturningNode(CfgNodes::ReturningCfgNode n) or TSsaDefinitionExtNode(SsaImpl::DefinitionExt def) or TCapturedVariableNode(VariableCapture::CapturedVariable v) or diff --git a/ruby/ql/lib/codeql/ruby/dataflow/internal/TaintTrackingPrivate.qll b/ruby/ql/lib/codeql/ruby/dataflow/internal/TaintTrackingPrivate.qll index 4786fd112597..a75567bccdf1 100644 --- a/ruby/ql/lib/codeql/ruby/dataflow/internal/TaintTrackingPrivate.qll +++ b/ruby/ql/lib/codeql/ruby/dataflow/internal/TaintTrackingPrivate.qll @@ -67,9 +67,10 @@ private CfgNodes::ExprNodes::VariableWriteAccessCfgNode variablesInPattern( cached private module Cached { private import codeql.ruby.dataflow.FlowSteps as FlowSteps + private import codeql.ruby.dataflow.internal.DataFlowImplCommon as DataFlowImplCommon cached - predicate forceCachingInSameStage() { any() } + predicate forceCachingInSameStage() { DataFlowImplCommon::forceCachingInSameStage() } /** * Holds if the additional step from `nodeFrom` to `nodeTo` should be included