Skip to content

Commit d1d2fae

Browse files
committed
Ruby: specialize filter-like calls
1 parent 22c3a28 commit d1d2fae

File tree

2 files changed

+15
-3
lines changed

2 files changed

+15
-3
lines changed

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

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ private import codeql.ruby.DataFlow
66
private import codeql.ruby.ast.internal.Module
77
private import codeql.ruby.dataflow.FlowSummary
88
private import codeql.ruby.dataflow.internal.DataFlowDispatch
9+
private import codeql.ruby.typetracking.TypeTrackerSpecific
910

1011
/** An array index that may be tracked precisely in data flow. */
1112
private class ArrayIndex extends int {
@@ -2471,6 +2472,20 @@ module Enumerable {
24712472
}
24722473
}
24732474

2475+
private class FilterTypeTrackingStep extends TypeTrackingStep {
2476+
override predicate withContentStep(Node pred, Node succ, ContentFilter filter) {
2477+
// Type-tracking cannot currently handle the `WithoutElement[0..!].WithElement[any]`
2478+
// sequence with full precision, so manually add it as a `WithContent` step.
2479+
exists(DataFlow::CallNode call |
2480+
call.asExpr().getExpr() =
2481+
[any(SelectSummary s).getACallSimple(), any(RejectSummary s).getACallSimple()] and
2482+
pred = call.getReceiver() and
2483+
succ = call and
2484+
filter = ContentFilter::hasElements()
2485+
)
2486+
}
2487+
}
2488+
24742489
private class SliceBeforeAfterSummary extends SimpleSummarizedCallable {
24752490
SliceBeforeAfterSummary() { this = ["slice_before", "slice_after"] }
24762491

ruby/ql/test/library-tests/dataflow/hash-flow/type-tracking-hash-flow.expected

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,17 +11,14 @@
1111
| hash_flow.rb:219:27:219:47 | # $ hasValueFlow=14.2 | Missing result:hasValueFlow=14.2 |
1212
| hash_flow.rb:291:10:291:14 | ...[...] | Unexpected result: hasValueFlow=19.1 |
1313
| hash_flow.rb:294:10:294:14 | ...[...] | Unexpected result: hasValueFlow=19.3 |
14-
| hash_flow.rb:351:18:351:38 | # $ hasValueFlow=22.1 | Missing result:hasValueFlow=22.1 |
1514
| hash_flow.rb:396:18:396:38 | # $ hasValueFlow=25.1 | Missing result:hasValueFlow=25.1 |
1615
| hash_flow.rb:453:22:453:42 | # $ hasValueFlow=27.3 | Missing result:hasValueFlow=27.3 |
1716
| hash_flow.rb:455:22:455:42 | # $ hasValueFlow=27.4 | Missing result:hasValueFlow=27.4 |
1817
| hash_flow.rb:467:16:467:36 | # $ hasValueFlow=28.1 | Missing result:hasValueFlow=28.1 |
19-
| hash_flow.rb:482:16:482:36 | # $ hasValueFlow=29.1 | Missing result:hasValueFlow=29.1 |
2018
| hash_flow.rb:497:16:497:36 | # $ hasValueFlow=30.1 | Missing result:hasValueFlow=30.1 |
2119
| hash_flow.rb:513:22:513:42 | # $ hasValueFlow=31.1 | Missing result:hasValueFlow=31.1 |
2220
| hash_flow.rb:515:10:515:20 | ( ... ) | Unexpected result: hasValueFlow=31.3 |
2321
| hash_flow.rb:515:22:515:42 | # $ hasValueFlow=31.2 | Missing result:hasValueFlow=31.2 |
24-
| hash_flow.rb:529:18:529:38 | # $ hasValueFlow=32.1 | Missing result:hasValueFlow=32.1 |
2522
| hash_flow.rb:559:17:559:57 | # $ hasValueFlow=34.1 $ hasValueFlow=34.2 | Missing result:hasValueFlow=34.1 |
2623
| hash_flow.rb:559:17:559:57 | # $ hasValueFlow=34.1 $ hasValueFlow=34.2 | Missing result:hasValueFlow=34.2 |
2724
| hash_flow.rb:571:18:571:38 | # $ hasValueFlow=35.1 | Missing result:hasValueFlow=35.1 |

0 commit comments

Comments
 (0)