Skip to content

Commit 6bae03a

Browse files
committed
Ruby: Update string const barrier guard
This change recognises guards like `FOO.include?`, where `FOO` is an array constant.
1 parent 13a0ece commit 6bae03a

File tree

2 files changed

+3
-1
lines changed

2 files changed

+3
-1
lines changed

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,8 @@ class StringConstArrayInclusionCall extends DataFlow::BarrierGuard,
6464
StringConstArrayInclusionCall() {
6565
exists(ArrayLiteral aLit |
6666
this.getExpr().getMethodName() = "include?" and
67-
this.getExpr().getReceiver() = aLit
67+
[this.getExpr().getReceiver(), this.getExpr().getReceiver().(ConstantReadAccess).getValue()] =
68+
aLit
6869
|
6970
forall(Expr elem | elem = aLit.getAnElement() | elem instanceof StringLiteral) and
7071
this.getArgument(0) = checkedNode

ruby/ql/test/library-tests/dataflow/barrier-guards/barrier-guards.expected

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,4 @@
33
| barrier-guards.rb:15:4:15:15 | ... != ... | barrier-guards.rb:18:5:18:7 | foo | barrier-guards.rb:15:4:15:6 | foo | false |
44
| barrier-guards.rb:21:8:21:19 | ... == ... | barrier-guards.rb:24:5:24:7 | foo | barrier-guards.rb:21:8:21:10 | foo | true |
55
| barrier-guards.rb:27:8:27:19 | ... != ... | barrier-guards.rb:28:5:28:7 | foo | barrier-guards.rb:27:8:27:10 | foo | false |
6+
| barrier-guards.rb:37:4:37:20 | call to include? | barrier-guards.rb:38:5:38:7 | foo | barrier-guards.rb:37:17:37:19 | foo | true |

0 commit comments

Comments
 (0)