Skip to content

Commit 912aa46

Browse files
authored
Merge pull request #11654 from hvitved/ruby/stage-collapse
Ruby: Ensure `Node::{toString,getLocation}` are computed in data flow stage
2 parents 2bdc9e8 + 5854908 commit 912aa46

File tree

3 files changed

+18
-15
lines changed

3 files changed

+18
-15
lines changed

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

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -340,6 +340,12 @@ private module Cached {
340340
p.(KeywordParameter).getDefaultValue() = e.getExprNode().getExpr()
341341
}
342342

343+
cached
344+
Location getLocation(NodeImpl n) { result = n.getLocationImpl() }
345+
346+
cached
347+
string toString(NodeImpl n) { result = n.toStringImpl() }
348+
343349
/**
344350
* This is the local flow predicate that is used as a building block in global
345351
* data flow.

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

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,10 @@ class Node extends TNode {
1919
Parameter asParameter() { result = this.(ParameterNode).getParameter() }
2020

2121
/** Gets a textual representation of this node. */
22-
cached
23-
final string toString() { result = this.(NodeImpl).toStringImpl() }
22+
final string toString() { result = toString(this) }
2423

2524
/** Gets the location of this node. */
26-
cached
27-
final Location getLocation() { result = this.(NodeImpl).getLocationImpl() }
25+
final Location getLocation() { result = getLocation(this) }
2826

2927
/**
3028
* Holds if this element is at the specified location.

ruby/ql/lib/codeql/ruby/frameworks/core/Array.qll

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -140,10 +140,9 @@ module Array {
140140
}
141141
}
142142

143-
private class SetDifferenceSummary extends SummarizedCallable {
144-
SetDifferenceSummary() { this = "-" }
145-
146-
override SubExpr getACallSimple() { any() }
143+
abstract private class DifferenceSummaryShared extends SummarizedCallable {
144+
bindingset[this]
145+
DifferenceSummaryShared() { any() }
147146

148147
override predicate propagatesFlowExt(string input, string output, boolean preservesValue) {
149148
input = "Argument[self].Element[any]" and
@@ -152,6 +151,12 @@ module Array {
152151
}
153152
}
154153

154+
private class SetDifferenceSummary extends DifferenceSummaryShared {
155+
SetDifferenceSummary() { this = "-" }
156+
157+
override SubExpr getACallSimple() { any() }
158+
}
159+
155160
/** Flow summary for `Array#<<`. For `Array#append`, see `PushSummary`. */
156161
private class AppendOperatorSummary extends SummarizedCallable {
157162
AppendOperatorSummary() { this = "<<" }
@@ -687,14 +692,8 @@ module Array {
687692
}
688693
}
689694

690-
private class DifferenceSummary extends SimpleSummarizedCallable {
695+
private class DifferenceSummary extends DifferenceSummaryShared, SimpleSummarizedCallable {
691696
DifferenceSummary() { this = "difference" }
692-
693-
override predicate propagatesFlowExt(string input, string output, boolean preservesValue) {
694-
// `Array#difference` and `Array#-` do not behave exactly the same way,
695-
// but we model their flow the same way.
696-
any(SetDifferenceSummary s).propagatesFlowExt(input, output, preservesValue)
697-
}
698697
}
699698

700699
private string getDigArg(MethodCall dig, int i) {

0 commit comments

Comments
 (0)