Skip to content

Commit 2fa1880

Browse files
authored
Merge pull request github#7665 from github/hmac/barrier-guard-array-const
2 parents c41de33 + 6bae03a commit 2fa1880

File tree

3 files changed

+11
-1
lines changed

3 files changed

+11
-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 |

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

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,3 +31,11 @@
3131
end
3232

3333
foo
34+
35+
FOO = ["foo"]
36+
37+
if FOO.include?(foo)
38+
foo
39+
else
40+
foo
41+
end

0 commit comments

Comments
 (0)