Skip to content

Commit 0fbb6bf

Browse files
committed
Ruby: Make array inclusion barrier more sensitive
1 parent c513867 commit 0fbb6bf

File tree

3 files changed

+22
-2
lines changed

3 files changed

+22
-2
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ private predicate stringConstArrayInclusionCall(
116116
isArrayConstant(t.getContainerNode().asExpr(), arr)
117117
|
118118
forall(ExprCfgNode elem | elem = arr.getAnArgument() |
119-
elem instanceof ExprNodes::StringLiteralCfgNode
119+
elem.getConstantValue().isStringlikeValue(_)
120120
)
121121
)
122122
)

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

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@ oldStyleBarrierGuards
1919
| barrier-guards.rb:232:6:232:17 | ... == ... | barrier-guards.rb:233:5:233:7 | foo | barrier-guards.rb:232:6:232:8 | foo | true |
2020
| barrier-guards.rb:237:6:237:17 | ... == ... | barrier-guards.rb:237:24:237:26 | foo | barrier-guards.rb:237:6:237:8 | foo | true |
2121
| barrier-guards.rb:268:1:268:12 | ... == ... | barrier-guards.rb:268:17:268:19 | foo | barrier-guards.rb:268:1:268:3 | foo | true |
22+
| barrier-guards.rb:271:4:271:19 | call to include? | barrier-guards.rb:272:5:272:7 | foo | barrier-guards.rb:271:17:271:19 | foo | true |
23+
| barrier-guards.rb:277:4:277:20 | call to include? | barrier-guards.rb:278:5:278:7 | foo | barrier-guards.rb:277:18:277:20 | foo | true |
2224
newStyleBarrierGuards
2325
| barrier-guards.rb:4:5:4:7 | foo |
2426
| barrier-guards.rb:10:5:10:7 | foo |
@@ -50,6 +52,8 @@ newStyleBarrierGuards
5052
| barrier-guards.rb:237:24:237:26 | foo |
5153
| barrier-guards.rb:244:5:244:7 | foo |
5254
| barrier-guards.rb:268:17:268:19 | foo |
55+
| barrier-guards.rb:272:5:272:7 | foo |
56+
| barrier-guards.rb:278:5:278:7 | foo |
5357
controls
5458
| barrier-guards.rb:3:4:3:15 | ... == ... | barrier-guards.rb:4:5:4:7 | foo | true |
5559
| barrier-guards.rb:3:4:3:15 | ... == ... | barrier-guards.rb:6:5:6:7 | foo | false |
@@ -317,8 +321,14 @@ controls
317321
| barrier-guards.rb:250:4:250:8 | "foo" | barrier-guards.rb:268:17:268:19 | foo | match |
318322
| barrier-guards.rb:250:4:250:8 | "foo" | barrier-guards.rb:269:1:269:19 | ... && ... | match |
319323
| barrier-guards.rb:250:4:250:8 | "foo" | barrier-guards.rb:269:8:269:10 | foo | match |
324+
| barrier-guards.rb:250:4:250:8 | "foo" | barrier-guards.rb:271:1:273:3 | if ... | match |
325+
| barrier-guards.rb:250:4:250:8 | "foo" | barrier-guards.rb:272:5:272:7 | foo | match |
326+
| barrier-guards.rb:250:4:250:8 | "foo" | barrier-guards.rb:277:1:279:3 | if ... | match |
327+
| barrier-guards.rb:250:4:250:8 | "foo" | barrier-guards.rb:278:5:278:7 | foo | match |
320328
| barrier-guards.rb:254:4:254:28 | ... == ... | barrier-guards.rb:255:5:255:7 | foo | true |
321329
| barrier-guards.rb:259:4:259:16 | ... == ... | barrier-guards.rb:260:5:260:7 | foo | true |
322330
| barrier-guards.rb:264:4:264:16 | ... == ... | barrier-guards.rb:265:5:265:7 | foo | true |
323331
| barrier-guards.rb:268:1:268:12 | ... == ... | barrier-guards.rb:268:17:268:19 | foo | true |
324332
| barrier-guards.rb:269:1:269:3 | foo | barrier-guards.rb:269:8:269:10 | foo | true |
333+
| barrier-guards.rb:271:4:271:19 | call to include? | barrier-guards.rb:272:5:272:7 | foo | true |
334+
| barrier-guards.rb:277:4:277:20 | call to include? | barrier-guards.rb:278:5:278:7 | foo | true |

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

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -266,4 +266,14 @@
266266
end
267267

268268
foo == "foo" && foo # $ guarded
269-
foo && foo == "foo"
269+
foo && foo == "foo"
270+
271+
if [f].include? foo
272+
foo # $ guarded
273+
end
274+
275+
g = "g"
276+
foos = [f, g]
277+
if foos.include? foo
278+
foo # $ guarded
279+
end

0 commit comments

Comments
 (0)