Skip to content

Commit 84d0e49

Browse files
committed
Ruby: Add more callback flow tests
1 parent 4ae35d1 commit 84d0e49

File tree

3 files changed

+71
-0
lines changed

3 files changed

+71
-0
lines changed

ruby/ql/test/library-tests/dataflow/global/Flow.expected

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,23 @@
11
testFailures
2+
| callbacks.rb:18:25:18:25 | x | Unexpected result: hasValueFlow=1 |
3+
| callbacks.rb:29:37:29:37 | x | Unexpected result: hasValueFlow=2 |
24
edges
5+
| callbacks.rb:9:15:9:15 | x | callbacks.rb:10:12:10:12 | x |
6+
| callbacks.rb:10:12:10:12 | x | callbacks.rb:17:15:17:15 | x |
7+
| callbacks.rb:10:12:10:12 | x | callbacks.rb:18:15:18:15 | x |
8+
| callbacks.rb:13:20:13:20 | x | callbacks.rb:14:14:14:14 | x |
9+
| callbacks.rb:14:14:14:14 | x | callbacks.rb:9:15:9:15 | x |
10+
| callbacks.rb:17:15:17:15 | x | callbacks.rb:17:25:17:25 | x |
11+
| callbacks.rb:17:31:17:38 | call to taint | callbacks.rb:13:20:13:20 | x |
12+
| callbacks.rb:18:15:18:15 | x | callbacks.rb:18:25:18:25 | x |
13+
| callbacks.rb:20:17:20:17 | x | callbacks.rb:21:11:21:11 | x |
14+
| callbacks.rb:21:11:21:11 | x | callbacks.rb:28:31:28:31 | x |
15+
| callbacks.rb:21:11:21:11 | x | callbacks.rb:29:29:29:29 | x |
16+
| callbacks.rb:24:23:24:23 | x | callbacks.rb:25:17:25:17 | x |
17+
| callbacks.rb:25:17:25:17 | x | callbacks.rb:20:17:20:17 | x |
18+
| callbacks.rb:28:18:28:25 | call to taint | callbacks.rb:24:23:24:23 | x |
19+
| callbacks.rb:28:31:28:31 | x | callbacks.rb:28:39:28:39 | x |
20+
| callbacks.rb:29:29:29:29 | x | callbacks.rb:29:37:29:37 | x |
321
| captured_variables.rb:9:24:9:24 | x | captured_variables.rb:10:10:10:23 | -> { ... } [captured x] |
422
| captured_variables.rb:9:24:9:24 | x | captured_variables.rb:11:5:11:6 | fn [captured x] |
523
| captured_variables.rb:10:5:10:6 | fn [captured x] | captured_variables.rb:11:5:11:6 | fn [captured x] |
@@ -253,6 +271,24 @@ edges
253271
| instance_variables.rb:121:1:121:3 | bar | instance_variables.rb:122:6:122:8 | bar |
254272
| instance_variables.rb:121:7:121:24 | call to new | instance_variables.rb:121:1:121:3 | bar |
255273
nodes
274+
| callbacks.rb:9:15:9:15 | x | semmle.label | x |
275+
| callbacks.rb:10:12:10:12 | x | semmle.label | x |
276+
| callbacks.rb:13:20:13:20 | x | semmle.label | x |
277+
| callbacks.rb:14:14:14:14 | x | semmle.label | x |
278+
| callbacks.rb:17:15:17:15 | x | semmle.label | x |
279+
| callbacks.rb:17:25:17:25 | x | semmle.label | x |
280+
| callbacks.rb:17:31:17:38 | call to taint | semmle.label | call to taint |
281+
| callbacks.rb:18:15:18:15 | x | semmle.label | x |
282+
| callbacks.rb:18:25:18:25 | x | semmle.label | x |
283+
| callbacks.rb:20:17:20:17 | x | semmle.label | x |
284+
| callbacks.rb:21:11:21:11 | x | semmle.label | x |
285+
| callbacks.rb:24:23:24:23 | x | semmle.label | x |
286+
| callbacks.rb:25:17:25:17 | x | semmle.label | x |
287+
| callbacks.rb:28:18:28:25 | call to taint | semmle.label | call to taint |
288+
| callbacks.rb:28:31:28:31 | x | semmle.label | x |
289+
| callbacks.rb:28:39:28:39 | x | semmle.label | x |
290+
| callbacks.rb:29:29:29:29 | x | semmle.label | x |
291+
| callbacks.rb:29:37:29:37 | x | semmle.label | x |
256292
| captured_variables.rb:9:24:9:24 | x | semmle.label | x |
257293
| captured_variables.rb:10:5:10:6 | fn [captured x] | semmle.label | fn [captured x] |
258294
| captured_variables.rb:10:10:10:23 | -> { ... } [captured x] | semmle.label | -> { ... } [captured x] |
@@ -548,6 +584,10 @@ subpaths
548584
| instance_variables.rb:120:6:120:10 | foo16 [@field] | captured_variables.rb:60:5:62:7 | self in get_field [@field] | captured_variables.rb:61:9:61:21 | return | instance_variables.rb:120:6:120:20 | call to get_field |
549585
| instance_variables.rb:120:6:120:10 | foo16 [@field] | instance_variables.rb:13:5:15:7 | self in get_field [@field] | instance_variables.rb:14:9:14:21 | return | instance_variables.rb:120:6:120:20 | call to get_field |
550586
#select
587+
| callbacks.rb:17:25:17:25 | x | callbacks.rb:17:31:17:38 | call to taint | callbacks.rb:17:25:17:25 | x | $@ | callbacks.rb:17:31:17:38 | call to taint | call to taint |
588+
| callbacks.rb:18:25:18:25 | x | callbacks.rb:17:31:17:38 | call to taint | callbacks.rb:18:25:18:25 | x | $@ | callbacks.rb:17:31:17:38 | call to taint | call to taint |
589+
| callbacks.rb:28:39:28:39 | x | callbacks.rb:28:18:28:25 | call to taint | callbacks.rb:28:39:28:39 | x | $@ | callbacks.rb:28:18:28:25 | call to taint | call to taint |
590+
| callbacks.rb:29:37:29:37 | x | callbacks.rb:28:18:28:25 | call to taint | callbacks.rb:29:37:29:37 | x | $@ | callbacks.rb:28:18:28:25 | call to taint | call to taint |
551591
| captured_variables.rb:10:20:10:20 | x | captured_variables.rb:13:20:13:29 | call to taint | captured_variables.rb:10:20:10:20 | x | $@ | captured_variables.rb:13:20:13:29 | call to taint | call to taint |
552592
| captured_variables.rb:17:14:17:14 | x | captured_variables.rb:20:25:20:34 | call to taint | captured_variables.rb:17:14:17:14 | x | $@ | captured_variables.rb:20:25:20:34 | call to taint | call to taint |
553593
| captured_variables.rb:24:14:24:14 | x | captured_variables.rb:27:48:27:57 | call to taint | captured_variables.rb:24:14:24:14 | x | $@ | captured_variables.rb:27:48:27:57 | call to taint | call to taint |

ruby/ql/test/library-tests/dataflow/global/TypeTrackingInlineTest.expected

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
testFailures
2+
| callbacks.rb:17:41:17:58 | # $ hasValueFlow=1 | Missing result:hasValueFlow=1 |
3+
| callbacks.rb:29:37:29:37 | x | Unexpected result: hasValueFlow=2 |
24
| captured_variables.rb:50:10:50:10 | x | Fixed missing result:hasValueFlow=2 |
35
| captured_variables.rb:68:25:68:68 | # $ hasValueFlow=3 $ MISSING: hasValueFlow=4 | Missing result:hasValueFlow=3 |
46
| captured_variables.rb:72:21:72:66 | # $ hasValueFlow=4 $ SPURIOUS: hasValueFlow=3 | Fixed spurious result:hasValueFlow=3 |
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
def taint x
2+
x
3+
end
4+
5+
def sink x
6+
puts "SINK: #{x}"
7+
end
8+
9+
def apply (f, x)
10+
f.call(x)
11+
end
12+
13+
def apply_wrap (f, x)
14+
apply(f, x)
15+
end
16+
17+
apply_wrap(->(x) { sink(x) }, taint(1)) # $ hasValueFlow=1
18+
apply_wrap(->(x) { sink(x) }, "safe")
19+
20+
def apply_block x
21+
yield x
22+
end
23+
24+
def apply_block_wrap (x, &block)
25+
apply_block(x, &block)
26+
end
27+
28+
apply_block_wrap(taint(2)) { |x| sink(x) } # $ hasValueFlow=2
29+
apply_block_wrap("safe") { |x| sink(x) }

0 commit comments

Comments
 (0)