Skip to content

Commit 0ab88c2

Browse files
committed
Ruby: Handle simple in clauses in barrier guard
1 parent 87944a3 commit 0ab88c2

File tree

3 files changed

+31
-0
lines changed

3 files changed

+31
-0
lines changed

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

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -187,5 +187,14 @@ private predicate stringConstCaseCompare(
187187
)
188188
)
189189
)
190+
or
191+
// in "foo"
192+
exists(
193+
CfgNodes::ExprNodes::InClauseCfgNode branchNode, ExprNodes::StringLiteralCfgNode pattern
194+
|
195+
branchNode = case.getBranch(_) and
196+
pattern = branchNode.getPattern() and
197+
guard = pattern
198+
)
190199
)
191200
}

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

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ newStyleBarrierGuards
3131
| barrier-guards.rb:164:5:164:7 | foo |
3232
| barrier-guards.rb:197:5:197:7 | foo |
3333
| barrier-guards.rb:201:24:201:26 | foo |
34+
| barrier-guards.rb:208:5:208:7 | foo |
3435
controls
3536
| barrier-guards.rb:3:4:3:15 | ... == ... | barrier-guards.rb:4:5:4:7 | foo | true |
3637
| barrier-guards.rb:3:4:3:15 | ... == ... | barrier-guards.rb:6:5:6:7 | foo | false |
@@ -110,3 +111,15 @@ controls
110111
| barrier-guards.rb:191:20:191:31 | ... == ... | barrier-guards.rb:191:4:191:31 | [false] ... or ... | false |
111112
| barrier-guards.rb:196:6:196:17 | ... == ... | barrier-guards.rb:197:5:197:7 | foo | true |
112113
| barrier-guards.rb:201:6:201:17 | ... == ... | barrier-guards.rb:201:24:201:26 | foo | true |
114+
| barrier-guards.rb:201:6:201:17 | ... == ... | barrier-guards.rb:202:1:202:26 | when ... | false |
115+
| barrier-guards.rb:201:6:201:17 | ... == ... | barrier-guards.rb:202:24:202:26 | foo | false |
116+
| barrier-guards.rb:201:6:201:17 | ... == ... | barrier-guards.rb:203:1:203:22 | when ... | false |
117+
| barrier-guards.rb:201:6:201:17 | ... == ... | barrier-guards.rb:203:20:203:22 | foo | false |
118+
| barrier-guards.rb:202:6:202:17 | ... == ... | barrier-guards.rb:202:24:202:26 | foo | true |
119+
| barrier-guards.rb:202:6:202:17 | ... == ... | barrier-guards.rb:203:1:203:22 | when ... | false |
120+
| barrier-guards.rb:202:6:202:17 | ... == ... | barrier-guards.rb:203:20:203:22 | foo | false |
121+
| barrier-guards.rb:203:6:203:13 | ... == ... | barrier-guards.rb:203:20:203:22 | foo | true |
122+
| barrier-guards.rb:207:4:207:8 | "foo" | barrier-guards.rb:208:5:208:7 | foo | match |
123+
| barrier-guards.rb:207:4:207:8 | "foo" | barrier-guards.rb:209:1:210:7 | in ... then ... | no-match |
124+
| barrier-guards.rb:207:4:207:8 | "foo" | barrier-guards.rb:210:5:210:7 | foo | no-match |
125+
| barrier-guards.rb:209:4:209:4 | x | barrier-guards.rb:210:5:210:7 | foo | match |

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

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -199,4 +199,13 @@
199199

200200
case
201201
when foo == "foo" then foo
202+
when bar == "bar" then foo
203+
when foo == x then foo
204+
end
205+
206+
case foo
207+
in "foo"
208+
foo
209+
in x
210+
foo
202211
end

0 commit comments

Comments
 (0)