Skip to content

Commit 25ceeaf

Browse files
committed
Ruby: Fix SplatExprCfgNode
1 parent 4bc9096 commit 25ceeaf

File tree

2 files changed

+10
-7
lines changed

2 files changed

+10
-7
lines changed

ruby/ql/lib/codeql/ruby/controlflow/CfgNodes.qll

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -866,15 +866,19 @@ module ExprNodes {
866866
final override RelationalOperation getExpr() { result = super.getExpr() }
867867
}
868868

869+
private class SplatExprChildMapping extends ExprChildMapping, SplatExpr {
870+
override predicate relevantChild(AstNode n) { n = this.getOperand() }
871+
}
872+
869873
/** A control-flow node that wraps a `SplatExpr` AST expression. */
870874
class SplatExprCfgNode extends ExprCfgNode {
871875
override string getAPrimaryQlClass() { result = "SplatExprCfgNode" }
872876

873-
SplatExprCfgNode() { e instanceof SplatExpr }
877+
override SplatExprChildMapping e;
874878

875879
final override SplatExpr getExpr() { result = super.getExpr() }
876880

877-
final ExprCfgNode getOperand() { result.getExpr() = e.(SplatExpr).getOperand() }
881+
final ExprCfgNode getOperand() { e.hasCfgChild(e.getOperand(), this, result) }
878882
}
879883

880884
/** A control-flow node that wraps an `ElementReference` AST expression. */

ruby/ql/lib/codeql/ruby/dataflow/BarrierGuards.qll

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -168,13 +168,12 @@ private predicate stringConstCaseCompare(
168168
// when "foo", "bar"
169169
pattern instanceof ExprNodes::StringLiteralCfgNode
170170
or
171-
// array literals behave weirdly in the CFG so we need to drop down to the AST level for this bit
172-
// specifically: `SplatExprCfgNode.getOperand()` does not return results for array literals
173171
exists(CfgNodes::ExprNodes::SplatExprCfgNode splat | splat = pattern |
174172
// when *["foo", "bar"]
175-
exists(ArrayLiteral arr |
176-
splat.getExpr().getOperand() = arr and
177-
forall(Expr elem | elem = arr.getAnElement() | elem instanceof StringLiteral)
173+
forex(ExprCfgNode elem |
174+
elem = splat.getOperand().(ExprNodes::ArrayLiteralCfgNode).getAnArgument()
175+
|
176+
elem instanceof ExprNodes::StringLiteralCfgNode
178177
)
179178
or
180179
// when *some_var

0 commit comments

Comments
 (0)