Skip to content

Commit 0f0acc0

Browse files
committed
Ruby: Add barrier guard flow tests
1 parent f025430 commit 0f0acc0

File tree

4 files changed

+177
-0
lines changed

4 files changed

+177
-0
lines changed
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
testFailures
2+
edges
3+
| barrier_flow.rb:2:5:2:5 | x | barrier_flow.rb:4:10:4:10 | x | provenance | |
4+
| barrier_flow.rb:2:9:2:17 | call to source | barrier_flow.rb:2:5:2:5 | x | provenance | |
5+
| barrier_flow.rb:8:5:8:5 | x | barrier_flow.rb:11:14:11:14 | x | provenance | |
6+
| barrier_flow.rb:8:9:8:17 | call to source | barrier_flow.rb:8:5:8:5 | x | provenance | |
7+
| barrier_flow.rb:24:5:24:5 | x | barrier_flow.rb:26:10:26:10 | x | provenance | |
8+
| barrier_flow.rb:24:9:24:17 | call to source | barrier_flow.rb:24:5:24:5 | x | provenance | |
9+
| barrier_flow.rb:36:5:36:5 | x | barrier_flow.rb:42:10:42:10 | x | provenance | |
10+
| barrier_flow.rb:36:9:36:17 | call to source | barrier_flow.rb:36:5:36:5 | x | provenance | |
11+
| barrier_flow.rb:46:5:46:5 | x | barrier_flow.rb:50:10:50:10 | x | provenance | |
12+
| barrier_flow.rb:46:9:46:17 | call to source | barrier_flow.rb:46:5:46:5 | x | provenance | |
13+
| barrier_flow.rb:54:5:54:5 | x | barrier_flow.rb:62:10:62:10 | x | provenance | |
14+
| barrier_flow.rb:54:9:54:17 | call to source | barrier_flow.rb:54:5:54:5 | x | provenance | |
15+
| barrier_flow.rb:66:5:66:5 | x | barrier_flow.rb:78:10:78:10 | x | provenance | |
16+
| barrier_flow.rb:66:9:66:17 | call to source | barrier_flow.rb:66:5:66:5 | x | provenance | |
17+
nodes
18+
| barrier_flow.rb:2:5:2:5 | x | semmle.label | x |
19+
| barrier_flow.rb:2:9:2:17 | call to source | semmle.label | call to source |
20+
| barrier_flow.rb:4:10:4:10 | x | semmle.label | x |
21+
| barrier_flow.rb:8:5:8:5 | x | semmle.label | x |
22+
| barrier_flow.rb:8:9:8:17 | call to source | semmle.label | call to source |
23+
| barrier_flow.rb:11:14:11:14 | x | semmle.label | x |
24+
| barrier_flow.rb:24:5:24:5 | x | semmle.label | x |
25+
| barrier_flow.rb:24:9:24:17 | call to source | semmle.label | call to source |
26+
| barrier_flow.rb:26:10:26:10 | x | semmle.label | x |
27+
| barrier_flow.rb:36:5:36:5 | x | semmle.label | x |
28+
| barrier_flow.rb:36:9:36:17 | call to source | semmle.label | call to source |
29+
| barrier_flow.rb:42:10:42:10 | x | semmle.label | x |
30+
| barrier_flow.rb:46:5:46:5 | x | semmle.label | x |
31+
| barrier_flow.rb:46:9:46:17 | call to source | semmle.label | call to source |
32+
| barrier_flow.rb:50:10:50:10 | x | semmle.label | x |
33+
| barrier_flow.rb:54:5:54:5 | x | semmle.label | x |
34+
| barrier_flow.rb:54:9:54:17 | call to source | semmle.label | call to source |
35+
| barrier_flow.rb:62:10:62:10 | x | semmle.label | x |
36+
| barrier_flow.rb:66:5:66:5 | x | semmle.label | x |
37+
| barrier_flow.rb:66:9:66:17 | call to source | semmle.label | call to source |
38+
| barrier_flow.rb:78:10:78:10 | x | semmle.label | x |
39+
subpaths
40+
#select
41+
| barrier_flow.rb:4:10:4:10 | x | barrier_flow.rb:2:9:2:17 | call to source | barrier_flow.rb:4:10:4:10 | x | $@ | barrier_flow.rb:2:9:2:17 | call to source | call to source |
42+
| barrier_flow.rb:11:14:11:14 | x | barrier_flow.rb:8:9:8:17 | call to source | barrier_flow.rb:11:14:11:14 | x | $@ | barrier_flow.rb:8:9:8:17 | call to source | call to source |
43+
| barrier_flow.rb:26:10:26:10 | x | barrier_flow.rb:24:9:24:17 | call to source | barrier_flow.rb:26:10:26:10 | x | $@ | barrier_flow.rb:24:9:24:17 | call to source | call to source |
44+
| barrier_flow.rb:42:10:42:10 | x | barrier_flow.rb:36:9:36:17 | call to source | barrier_flow.rb:42:10:42:10 | x | $@ | barrier_flow.rb:36:9:36:17 | call to source | call to source |
45+
| barrier_flow.rb:50:10:50:10 | x | barrier_flow.rb:46:9:46:17 | call to source | barrier_flow.rb:50:10:50:10 | x | $@ | barrier_flow.rb:46:9:46:17 | call to source | call to source |
46+
| barrier_flow.rb:62:10:62:10 | x | barrier_flow.rb:54:9:54:17 | call to source | barrier_flow.rb:62:10:62:10 | x | $@ | barrier_flow.rb:54:9:54:17 | call to source | call to source |
47+
| barrier_flow.rb:78:10:78:10 | x | barrier_flow.rb:66:9:66:17 | call to source | barrier_flow.rb:78:10:78:10 | x | $@ | barrier_flow.rb:66:9:66:17 | call to source | call to source |
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
/**
2+
* @kind path-problem
3+
*/
4+
5+
import codeql.ruby.AST
6+
import codeql.ruby.CFG
7+
import TestUtilities.InlineFlowTest
8+
import codeql.ruby.dataflow.BarrierGuards
9+
import PathGraph
10+
11+
module FlowConfig implements DataFlow::ConfigSig {
12+
predicate isSource = DefaultFlowConfig::isSource/1;
13+
14+
predicate isSink = DefaultFlowConfig::isSink/1;
15+
16+
predicate isBarrier(DataFlow::Node n) { n instanceof StringConstCompareBarrier }
17+
}
18+
19+
import ValueFlowTest<FlowConfig>
20+
21+
from PathNode source, PathNode sink
22+
where flowPath(source, sink)
23+
select sink, source, sink, "$@", source, source.toString()

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

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,8 @@ newStyleBarrierGuards
3636
| barrier-guards.rb:276:5:276:7 | foo |
3737
| barrier-guards.rb:282:5:282:7 | foo |
3838
| barrier-guards.rb:292:5:292:7 | foo |
39+
| barrier_flow.rb:19:14:19:14 | x |
40+
| barrier_flow.rb:32:10:32:10 | x |
3941
controls
4042
| barrier-guards.rb:3:4:3:15 | ... == ... | barrier-guards.rb:4:5:4:7 | foo | true |
4143
| barrier-guards.rb:3:4:3:15 | ... == ... | barrier-guards.rb:6:5:6:7 | foo | false |
@@ -331,3 +333,29 @@ controls
331333
| barrier-guards.rb:291:6:291:6 | g | barrier-guards.rb:291:1:292:19 | [no-match] when ... | no-match |
332334
| barrier-guards.rb:291:6:291:6 | g | barrier-guards.rb:292:5:292:7 | foo | match |
333335
| barrier-guards.rb:291:6:291:6 | g | barrier-guards.rb:294:5:294:7 | foo | no-match |
336+
| barrier_flow.rb:10:8:10:18 | ... != ... | barrier_flow.rb:11:9:11:14 | self | true |
337+
| barrier_flow.rb:18:8:18:18 | ... == ... | barrier_flow.rb:19:9:19:14 | self | true |
338+
| barrier_flow.rb:26:19:26:29 | ... == ... | barrier_flow.rb:26:5:26:10 | self | false |
339+
| barrier_flow.rb:32:19:32:29 | ... != ... | barrier_flow.rb:32:5:32:10 | self | false |
340+
| barrier_flow.rb:38:8:38:18 | ... != ... | barrier_flow.rb:39:9:39:9 | x | true |
341+
| barrier_flow.rb:48:23:48:33 | ... == ... | barrier_flow.rb:48:5:48:5 | x | false |
342+
| barrier_flow.rb:56:8:56:8 | b | barrier_flow.rb:57:9:57:14 | return | true |
343+
| barrier_flow.rb:56:8:56:8 | b | barrier_flow.rb:57:9:57:34 | ... unless ... | true |
344+
| barrier_flow.rb:56:8:56:8 | b | barrier_flow.rb:57:23:57:23 | x | true |
345+
| barrier_flow.rb:56:8:56:8 | b | barrier_flow.rb:59:9:59:14 | return | false |
346+
| barrier_flow.rb:56:8:56:8 | b | barrier_flow.rb:59:9:59:34 | ... unless ... | false |
347+
| barrier_flow.rb:56:8:56:8 | b | barrier_flow.rb:59:23:59:23 | x | false |
348+
| barrier_flow.rb:57:23:57:34 | ... == ... | barrier_flow.rb:57:9:57:14 | return | false |
349+
| barrier_flow.rb:57:23:57:34 | ... == ... | barrier_flow.rb:57:9:57:34 | ... unless ... | true |
350+
| barrier_flow.rb:59:23:59:34 | ... == ... | barrier_flow.rb:59:9:59:14 | return | false |
351+
| barrier_flow.rb:59:23:59:34 | ... == ... | barrier_flow.rb:59:9:59:34 | ... unless ... | true |
352+
| barrier_flow.rb:68:8:68:8 | b | barrier_flow.rb:69:9:71:11 | if ... | true |
353+
| barrier_flow.rb:68:8:68:8 | b | barrier_flow.rb:69:12:69:12 | x | true |
354+
| barrier_flow.rb:68:8:68:8 | b | barrier_flow.rb:70:13:70:18 | return | true |
355+
| barrier_flow.rb:68:8:68:8 | b | barrier_flow.rb:73:9:75:11 | if ... | false |
356+
| barrier_flow.rb:68:8:68:8 | b | barrier_flow.rb:73:12:73:12 | x | false |
357+
| barrier_flow.rb:68:8:68:8 | b | barrier_flow.rb:74:13:74:18 | return | false |
358+
| barrier_flow.rb:69:12:69:23 | ... != ... | barrier_flow.rb:69:9:71:11 | if ... | false |
359+
| barrier_flow.rb:69:12:69:23 | ... != ... | barrier_flow.rb:70:13:70:18 | return | true |
360+
| barrier_flow.rb:73:12:73:23 | ... != ... | barrier_flow.rb:73:9:75:11 | if ... | false |
361+
| barrier_flow.rb:73:12:73:23 | ... != ... | barrier_flow.rb:74:13:74:18 | return | true |
Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
def m1
2+
x = source(1)
3+
4+
sink x # $ hasValueFlow=1
5+
end
6+
7+
def m2
8+
x = source(2)
9+
10+
if x != "safe" then
11+
sink x # $ hasValueFlow=2
12+
end
13+
end
14+
15+
def m3
16+
x = source(3)
17+
18+
if x == "safe" then
19+
sink x # $ guarded
20+
end
21+
end
22+
23+
def m4
24+
x = source(4)
25+
26+
sink x unless x == "safe" # $ hasValueFlow=4
27+
end
28+
29+
def m5
30+
x = source(5)
31+
32+
sink x unless x != "safe" # $ guarded
33+
end
34+
35+
def m6
36+
x = source(6)
37+
38+
if x != "safe" then
39+
x = "safe"
40+
end
41+
42+
sink x # $ SPURIOUS hasValueFlow=6
43+
end
44+
45+
def m7
46+
x = source(7)
47+
48+
x = "safe" unless x == "safe"
49+
50+
sink x # $ SPURIOUS hasValueFlow=7
51+
end
52+
53+
def m8(b)
54+
x = source(8)
55+
56+
if b then
57+
return unless x == "safe1"
58+
else
59+
return unless x == "safe2"
60+
end
61+
62+
sink x # $ SPURIOUS hasValueFlow=8
63+
end
64+
65+
def m9(b)
66+
x = source(9)
67+
68+
if b then
69+
if x != "safe1" then
70+
return
71+
end
72+
else
73+
if x != "safe2" then
74+
return
75+
end
76+
end
77+
78+
sink x # $ SPURIOUS hasValueFlow=9
79+
end

0 commit comments

Comments
 (0)