Skip to content

Commit 137594c

Browse files
committed
Ruby: Add regression test
1 parent cccb11f commit 137594c

File tree

3 files changed

+43
-0
lines changed

3 files changed

+43
-0
lines changed
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
| regressions.rb:2:1:2:9 | [post] call to reverse | regressions.rb:3:6:3:6 | x |
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
private import codeql.ruby.dataflow.FlowSummary
2+
3+
private class ReverseSummary extends SimpleSummarizedCallable {
4+
ReverseSummary() { this = "reverse" }
5+
6+
override predicate propagatesFlow(string input, string output, boolean preservesValue) {
7+
input = "Argument[self].WithElement[any]" and
8+
output = "ReturnValue" and
9+
preservesValue = true
10+
}
11+
}
12+
13+
private module Config implements DataFlow::ConfigSig {
14+
predicate isSource(DataFlow::Node source) {
15+
source
16+
.(DataFlow::PostUpdateNode)
17+
.getPreUpdateNode()
18+
.asExpr()
19+
.getExpr()
20+
.(MethodCall)
21+
.getMethodName() = "reverse"
22+
}
23+
24+
predicate isSink(DataFlow::Node sink) {
25+
exists(MethodCall mc |
26+
mc.getMethodName() = "sink" and
27+
sink.asExpr().getExpr() = mc.getAnArgument()
28+
)
29+
}
30+
}
31+
32+
/**
33+
* This predicate should not have a result. We check that the flow summary for
34+
* `reverse` does not get picked up by the `reverseStepThroughInputOutputAlias`
35+
* logic in `DataFlowImplCommon.qll`.
36+
*/
37+
query predicate noReverseStepThroughInputOutputAlias(DataFlow::Node source, DataFlow::Node sink) {
38+
DataFlow::Global<Config>::flow(source, sink)
39+
}
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
x = foo
2+
x.reverse.bar
3+
sink(x)

0 commit comments

Comments
 (0)