diff --git a/ruby/ql/lib/codeql/ruby/ast/Statement.qll b/ruby/ql/lib/codeql/ruby/ast/Statement.qll index b97dfb4e626ee..24e18fe4c362d 100644 --- a/ruby/ql/lib/codeql/ruby/ast/Statement.qll +++ b/ruby/ql/lib/codeql/ruby/ast/Statement.qll @@ -12,7 +12,7 @@ private import codeql.ruby.controlflow.internal.ControlFlowGraphImpl as CfgImpl */ class Stmt extends AstNode, TStmt { /** Gets a control-flow node for this statement, if any. */ - CfgNodes::AstCfgNode getAControlFlowNode() { result.getNode() = this } + CfgNodes::AstCfgNode getAControlFlowNode() { result.getAstNode() = this } /** Gets a control-flow entry node for this statement, if any */ AstNode getAControlFlowEntryNode() { result = CfgImpl::getAControlFlowEntryNode(this) } diff --git a/ruby/ql/lib/codeql/ruby/ast/internal/Constant.qll b/ruby/ql/lib/codeql/ruby/ast/internal/Constant.qll index d68a5582e1771..c18474df099ac 100644 --- a/ruby/ql/lib/codeql/ruby/ast/internal/Constant.qll +++ b/ruby/ql/lib/codeql/ruby/ast/internal/Constant.qll @@ -214,7 +214,7 @@ private module Propagation { any(StringComponentCfgNode c | isString(c, result) or - result = c.getNode().(StringComponentImpl).getValue() + result = c.getAstNode().(StringComponentImpl).getValue() ) } diff --git a/ruby/ql/lib/codeql/ruby/controlflow/BasicBlocks.qll b/ruby/ql/lib/codeql/ruby/controlflow/BasicBlocks.qll index 317cdd9e2e3cc..350f07a431a78 100644 --- a/ruby/ql/lib/codeql/ruby/controlflow/BasicBlocks.qll +++ b/ruby/ql/lib/codeql/ruby/controlflow/BasicBlocks.qll @@ -389,7 +389,7 @@ private module JoinBlockPredecessors { private predicate idOf(Ruby::AstNode x, int y) = equivalenceRelation(id/2)(x, y) int getId(JoinBlockPredecessor jbp) { - idOf(toGeneratedInclSynth(jbp.getFirstNode().(AstCfgNode).getNode()), result) + idOf(toGeneratedInclSynth(jbp.getFirstNode().(AstCfgNode).getAstNode()), result) or idOf(toGeneratedInclSynth(jbp.(EntryBasicBlock).getScope()), result) } diff --git a/ruby/ql/lib/codeql/ruby/controlflow/CfgNodes.qll b/ruby/ql/lib/codeql/ruby/controlflow/CfgNodes.qll index 768e9c90a5910..1a8c6bcc60790 100644 --- a/ruby/ql/lib/codeql/ruby/controlflow/CfgNodes.qll +++ b/ruby/ql/lib/codeql/ruby/controlflow/CfgNodes.qll @@ -46,7 +46,7 @@ class ExprCfgNode extends AstCfgNode { Expr e; - ExprCfgNode() { e = this.getNode() } + ExprCfgNode() { e = this.getAstNode() } /** Gets the underlying expression. */ Expr getExpr() { result = e } @@ -61,12 +61,12 @@ class ReturningCfgNode extends AstCfgNode { ReturningStmt s; - ReturningCfgNode() { s = this.getNode() } + ReturningCfgNode() { s = this.getAstNode() } /** Gets the node of the returned value, if any. */ ExprCfgNode getReturnedValueNode() { result = this.getAPredecessor() and - result.getNode() = s.getValue() + result.getAstNode() = s.getValue() } } @@ -74,17 +74,19 @@ class ReturningCfgNode extends AstCfgNode { class StringComponentCfgNode extends AstCfgNode { override string getAPrimaryQlClass() { result = "StringComponentCfgNode" } - StringComponentCfgNode() { this.getNode() instanceof StringComponent } + StringComponentCfgNode() { this.getAstNode() instanceof StringComponent } /** Gets the constant value of this string component. */ - ConstantValue getConstantValue() { result = this.getNode().(StringComponent).getConstantValue() } + ConstantValue getConstantValue() { + result = this.getAstNode().(StringComponent).getConstantValue() + } } /** A control-flow node that wraps a `RegExpComponent` AST expression. */ class RegExpComponentCfgNode extends StringComponentCfgNode { override string getAPrimaryQlClass() { result = "RegExpComponentCfgNode" } - RegExpComponentCfgNode() { this.getNode() instanceof RegExpComponent } + RegExpComponentCfgNode() { this.getAstNode() instanceof RegExpComponent } } private AstNode desugar(AstNode n) { @@ -117,7 +119,7 @@ abstract private class ChildMapping extends AstNode { cached predicate hasCfgChild(AstNode child, CfgNode cfn, CfgNode cfnChild) { this.reachesBasicBlock(child, cfn, cfnChild.getBasicBlock()) and - cfnChild.getNode() = desugar(child) + cfnChild.getAstNode() = desugar(child) } } @@ -134,7 +136,7 @@ abstract private class ExprChildMapping extends Expr, ChildMapping { exists(BasicBlock mid | this.reachesBasicBlock(child, cfn, mid) and bb = mid.getAPredecessor() and - not mid.getANode().getNode() = child + not mid.getANode().getAstNode() = child ) } } @@ -148,13 +150,13 @@ abstract private class NonExprChildMapping extends ChildMapping { pragma[nomagic] override predicate reachesBasicBlock(AstNode child, CfgNode cfn, BasicBlock bb) { this.relevantChild(child) and - cfn.getNode() = this and + cfn.getAstNode() = this and bb.getANode() = cfn or exists(BasicBlock mid | this.reachesBasicBlock(child, cfn, mid) and bb = mid.getASuccessor() and - not mid.getANode().getNode() = child + not mid.getANode().getAstNode() = child ) } } @@ -380,7 +382,7 @@ module ExprNodes { class InClauseCfgNode extends AstCfgNode { private InClauseChildMapping e; - InClauseCfgNode() { e = this.getNode() } + InClauseCfgNode() { e = this.getAstNode() } override string getAPrimaryQlClass() { result = "InClauseCfgNode" } @@ -400,28 +402,28 @@ module ExprNodes { predicate patternReachesBasicBlock(int i, CfgNode cfnPattern, BasicBlock bb) { exists(Expr pattern | pattern = this.getPattern(i) and - cfnPattern.getNode() = pattern and + cfnPattern.getAstNode() = pattern and bb.getANode() = cfnPattern ) or exists(BasicBlock mid | this.patternReachesBasicBlock(i, cfnPattern, mid) and bb = mid.getASuccessor() and - not mid.getANode().getNode() = this + not mid.getANode().getAstNode() = this ) } predicate bodyReachesBasicBlock(CfgNode cfnBody, BasicBlock bb) { exists(Stmt body | body = this.getBody() and - cfnBody.getNode() = body and + cfnBody.getAstNode() = body and bb.getANode() = cfnBody ) or exists(BasicBlock mid | this.bodyReachesBasicBlock(cfnBody, mid) and bb = mid.getAPredecessor() and - not mid.getANode().getNode() = this + not mid.getANode().getAstNode() = this ) } } @@ -430,19 +432,19 @@ module ExprNodes { class WhenClauseCfgNode extends AstCfgNode { private WhenClauseChildMapping e; - WhenClauseCfgNode() { e = this.getNode() } + WhenClauseCfgNode() { e = this.getAstNode() } override string getAPrimaryQlClass() { result = "WhenClauseCfgNode" } /** Gets the body of this `when`-clause. */ final ExprCfgNode getBody() { - result.getNode() = desugar(e.getBody()) and + result.getAstNode() = desugar(e.getBody()) and e.bodyReachesBasicBlock(result, this.getBasicBlock()) } /** Gets the `i`th pattern this `when`-clause. */ final ExprCfgNode getPattern(int i) { - result.getNode() = desugar(e.getPattern(i)) and + result.getAstNode() = desugar(e.getPattern(i)) and e.patternReachesBasicBlock(i, result, this.getBasicBlock()) } } @@ -451,7 +453,7 @@ module ExprNodes { class CasePatternCfgNode extends AstCfgNode { CasePattern e; - CasePatternCfgNode() { e = this.getNode() } + CasePatternCfgNode() { e = this.getAstNode() } override string getAPrimaryQlClass() { result = "CasePatternCfgNode" } } @@ -815,7 +817,7 @@ module ExprNodes { /** A control-flow node that wraps an `InstanceVariableReadAccess` AST expression. */ class InstanceVariableReadAccessCfgNode extends InstanceVariableAccessCfgNode { - InstanceVariableReadAccessCfgNode() { this.getNode() instanceof InstanceVariableReadAccess } + InstanceVariableReadAccessCfgNode() { this.getAstNode() instanceof InstanceVariableReadAccess } override string getAPrimaryQlClass() { result = "InstanceVariableReadAccessCfgNode" } @@ -824,7 +826,9 @@ module ExprNodes { /** A control-flow node that wraps an `InstanceVariableWriteAccess` AST expression. */ class InstanceVariableWriteAccessCfgNode extends InstanceVariableAccessCfgNode { - InstanceVariableWriteAccessCfgNode() { this.getNode() instanceof InstanceVariableWriteAccess } + InstanceVariableWriteAccessCfgNode() { + this.getAstNode() instanceof InstanceVariableWriteAccess + } override string getAPrimaryQlClass() { result = "InstanceVariableWriteAccessCfgNode" } @@ -835,7 +839,9 @@ module ExprNodes { class StringInterpolationComponentCfgNode extends StringComponentCfgNode, StmtSequenceCfgNode { override string getAPrimaryQlClass() { result = "StringInterpolationComponentCfgNode" } - StringInterpolationComponentCfgNode() { this.getNode() instanceof StringInterpolationComponent } + StringInterpolationComponentCfgNode() { + this.getAstNode() instanceof StringInterpolationComponent + } final override ConstantValue getConstantValue() { result = StmtSequenceCfgNode.super.getConstantValue() @@ -846,7 +852,9 @@ module ExprNodes { class RegExpInterpolationComponentCfgNode extends RegExpComponentCfgNode, StmtSequenceCfgNode { override string getAPrimaryQlClass() { result = "RegExpInterpolationComponentCfgNode" } - RegExpInterpolationComponentCfgNode() { this.getNode() instanceof RegExpInterpolationComponent } + RegExpInterpolationComponentCfgNode() { + this.getAstNode() instanceof RegExpInterpolationComponent + } final override ConstantValue getConstantValue() { result = StmtSequenceCfgNode.super.getConstantValue() diff --git a/ruby/ql/lib/codeql/ruby/controlflow/ControlFlowGraph.qll b/ruby/ql/lib/codeql/ruby/controlflow/ControlFlowGraph.qll index 39338b545e08f..9a386369e9198 100644 --- a/ruby/ql/lib/codeql/ruby/controlflow/ControlFlowGraph.qll +++ b/ruby/ql/lib/codeql/ruby/controlflow/ControlFlowGraph.qll @@ -40,6 +40,9 @@ class CfgNode extends CfgImpl::Node { /** Gets the file of this control flow node. */ final File getFile() { result = this.getLocation().getFile() } + /** DEPRECATED: Use `getAstNode` instead. */ + deprecated AstNode getNode() { result = this.getAstNode() } + /** Gets a successor node of a given type, if any. */ final CfgNode getASuccessor(SuccessorType t) { result = super.getASuccessor(t) } diff --git a/ruby/ql/lib/codeql/ruby/dataflow/internal/DataFlowDispatch.qll b/ruby/ql/lib/codeql/ruby/dataflow/internal/DataFlowDispatch.qll index 7408412aa9188..e020f17e8c727 100644 --- a/ruby/ql/lib/codeql/ruby/dataflow/internal/DataFlowDispatch.qll +++ b/ruby/ql/lib/codeql/ruby/dataflow/internal/DataFlowDispatch.qll @@ -264,7 +264,7 @@ private predicate selfInToplevel(SelfVariable self, Module m) { private predicate asModulePattern(SsaDefinitionExtNode def, Module m) { exists(AsPattern ap | m = resolveConstantReadAccess(ap.getPattern()) and - def.getDefinitionExt().(Ssa::WriteDefinition).getWriteAccess().getNode() = + def.getDefinitionExt().(Ssa::WriteDefinition).getWriteAccess().getAstNode() = ap.getVariableAccess() ) } diff --git a/ruby/ql/lib/codeql/ruby/dataflow/internal/DataFlowPrivate.qll b/ruby/ql/lib/codeql/ruby/dataflow/internal/DataFlowPrivate.qll index f8469e99a23a4..6bf7058bec7fd 100644 --- a/ruby/ql/lib/codeql/ruby/dataflow/internal/DataFlowPrivate.qll +++ b/ruby/ql/lib/codeql/ruby/dataflow/internal/DataFlowPrivate.qll @@ -118,7 +118,7 @@ module LocalFlow { /** Gets the SSA definition node corresponding to parameter `p`. */ SsaDefinitionExtNode getParameterDefNode(NamedParameter p) { exists(BasicBlock bb, int i | - bb.getNode(i).getNode() = p.getDefiningAccess() and + bb.getNode(i).getAstNode() = p.getDefiningAccess() and result.getDefinitionExt().definesAt(_, bb, i, _) ) } @@ -203,8 +203,8 @@ module LocalFlow { exists(CfgNodes::ExprCfgNode exprTo, ReturningStatementNode n | nodeFrom = n and exprTo = nodeTo.asExpr() and - n.getReturningNode().getNode() instanceof BreakStmt and - exprTo.getNode() instanceof Loop and + n.getReturningNode().getAstNode() instanceof BreakStmt and + exprTo.getAstNode() instanceof Loop and nodeTo.asExpr().getAPredecessor(any(SuccessorTypes::BreakSuccessor s)) = n.getReturningNode() ) or @@ -926,7 +926,7 @@ abstract class SourceReturnNode extends ReturnNode { private module ReturnNodes { private predicate isValid(CfgNodes::ReturningCfgNode node) { exists(ReturningStmt stmt, Callable scope | - stmt = node.getNode() and + stmt = node.getAstNode() and scope = node.getScope() | stmt instanceof ReturnStmt and @@ -952,7 +952,7 @@ private module ReturnNodes { } override ReturnKind getKindSource() { - if n.getNode() instanceof BreakStmt + if n.getAstNode() instanceof BreakStmt then result instanceof BreakReturnKind else exists(CfgScope scope | scope = this.getCfgScope() | diff --git a/ruby/ql/lib/codeql/ruby/dataflow/internal/SsaImpl.qll b/ruby/ql/lib/codeql/ruby/dataflow/internal/SsaImpl.qll index ca31135fb460d..9502f04a7eb64 100644 --- a/ruby/ql/lib/codeql/ruby/dataflow/internal/SsaImpl.qll +++ b/ruby/ql/lib/codeql/ruby/dataflow/internal/SsaImpl.qll @@ -31,7 +31,7 @@ private module SsaInput implements SsaImplCommon::InputSig { i = 0 or // ...or a class or module block. - bb.getNode(i).getNode() = scope.(ModuleBase).getAControlFlowEntryNode() and + bb.getNode(i).getAstNode() = scope.(ModuleBase).getAControlFlowEntryNode() and not scope instanceof Toplevel // handled by case above ) or @@ -126,8 +126,8 @@ private predicate namespaceSelfExitRead(Cfg::AnnotatedExitBasicBlock bb, int i, v.getDeclaringScope() = ns and last = ControlFlowGraphImpl::getAControlFlowExitNode(ns) and if last = ns - then bb.getNode(i).getAPredecessor().getNode() = last - else bb.getNode(i).getNode() = last + then bb.getNode(i).getAPredecessor().getAstNode() = last + else bb.getNode(i).getAstNode() = last ) } @@ -183,7 +183,7 @@ private predicate capturedCallRead(CallCfgNode call, Cfg::BasicBlock bb, int i, private predicate variableReadActual(Cfg::BasicBlock bb, int i, LocalVariable v) { exists(VariableReadAccess read | read.getVariable() = v and - read = bb.getNode(i).getNode() + read = bb.getNode(i).getAstNode() ) } diff --git a/ruby/ql/lib/codeql/ruby/frameworks/ActiveRecord.qll b/ruby/ql/lib/codeql/ruby/frameworks/ActiveRecord.qll index fcca078f933f0..731572894058c 100644 --- a/ruby/ql/lib/codeql/ruby/frameworks/ActiveRecord.qll +++ b/ruby/ql/lib/codeql/ruby/frameworks/ActiveRecord.qll @@ -210,7 +210,7 @@ class PotentiallyUnsafeSqlExecutingMethodCall extends ActiveRecordModelClassMeth class ActiveRecordSqlExecutionRange extends SqlExecution::Range { ActiveRecordSqlExecutionRange() { exists(PotentiallyUnsafeSqlExecutingMethodCall mc | - this.asExpr().getNode() = mc.getSqlFragmentSinkArgument() + this.asExpr().getAstNode() = mc.getSqlFragmentSinkArgument() ) or this = activeRecordConnectionInstance().getAMethodCall("execute").getArgument(0) and diff --git a/ruby/ql/lib/codeql/ruby/typetracking/TypeTrackerSpecific.qll b/ruby/ql/lib/codeql/ruby/typetracking/TypeTrackerSpecific.qll index d14c182d12731..256d15212d018 100644 --- a/ruby/ql/lib/codeql/ruby/typetracking/TypeTrackerSpecific.qll +++ b/ruby/ql/lib/codeql/ruby/typetracking/TypeTrackerSpecific.qll @@ -230,7 +230,7 @@ predicate returnStep(Node nodeFrom, Node nodeTo) { // deliberately do not include `getInitializeTarget`, since calls to `new` should not // get the return value from `initialize`. Any fields being set in the initializer // will reach all reads via `callStep` and `localFieldStep`. - nodeTo.asExpr().getNode() = call.getNode() + nodeTo.asExpr().getAstNode() = call.getAstNode() ) } diff --git a/ruby/ql/src/experimental/performance/UseDetect.ql b/ruby/ql/src/experimental/performance/UseDetect.ql index c58b544b97625..56ab99ae40563 100644 --- a/ruby/ql/src/experimental/performance/UseDetect.ql +++ b/ruby/ql/src/experimental/performance/UseDetect.ql @@ -42,12 +42,12 @@ class EndCall extends MethodCall { } Expr getUniqueRead(Expr e) { - forex(CfgNode eNode | eNode.getNode() = e | + forex(CfgNode eNode | eNode.getAstNode() = e | exists(Ssa::WriteDefinition def | def.assigns(eNode) and strictcount(def.getARead()) = 1 and not def = any(Ssa::PhiNode phi).getAnInput() and - def.getARead().getNode() = result + def.getARead().getAstNode() = result ) ) } diff --git a/ruby/ql/src/queries/analysis/Definitions.ql b/ruby/ql/src/queries/analysis/Definitions.ql index 5193111891235..a1a0d6b258b33 100644 --- a/ruby/ql/src/queries/analysis/Definitions.ql +++ b/ruby/ql/src/queries/analysis/Definitions.ql @@ -48,7 +48,7 @@ newtype DefLoc = /** A local variable. */ LocalVariableLoc(VariableReadAccess read, VariableWriteAccess write) { exists(Ssa::WriteDefinition w | - write = w.getWriteAccess().getNode() and + write = w.getWriteAccess().getAstNode() and read = w.getARead().getExpr() and not read.isSynthesized() ) diff --git a/shared/controlflow/codeql/controlflow/Cfg.qll b/shared/controlflow/codeql/controlflow/Cfg.qll index 6592db760fc49..592e4c9a4ec0c 100644 --- a/shared/controlflow/codeql/controlflow/Cfg.qll +++ b/shared/controlflow/codeql/controlflow/Cfg.qll @@ -971,7 +971,7 @@ module Make Input> { abstract string toString(); /** Gets the AST node that this node corresponds to, if any. */ - abstract AstNode getNode(); + abstract AstNode getAstNode(); /** Gets the location of this control flow node. */ abstract Location getLocation(); @@ -1011,7 +1011,7 @@ module Make Input> { EntryNodeImpl() { this = TEntryNode(scope) } - final override AstNode getNode() { none() } + final override AstNode getAstNode() { none() } final override Location getLocation() { result = scope.getLocation() } @@ -1030,7 +1030,7 @@ module Make Input> { /** Holds if this node represent a normal exit. */ final predicate isNormal() { normal = true } - final override AstNode getNode() { none() } + final override AstNode getAstNode() { none() } final override Location getLocation() { result = scope.getLocation() } @@ -1053,7 +1053,7 @@ module Make Input> { ExitNodeImpl() { this = TExitNode(scope) } - final override AstNode getNode() { none() } + final override AstNode getAstNode() { none() } final override Location getLocation() { result = scope.getLocation() } @@ -1075,7 +1075,7 @@ module Make Input> { AstCfgNodeImpl() { this = TAstNode(_, n, splits) } - final override AstNode getNode() { result = n } + final override AstNode getAstNode() { result = n } override Location getLocation() { result = n.getLocation() }