Skip to content

Commit 07910b0

Browse files
committed
Ruby: Add more callback flow tests
1 parent ca05697 commit 07910b0

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
@@ -5,6 +5,22 @@ edges
55
| blocks.rb:18:11:18:11 | x | blocks.rb:24:18:24:18 | x | provenance | |
66
| blocks.rb:24:3:24:11 | call to source | blocks.rb:17:10:17:10 | x | provenance | |
77
| blocks.rb:24:18:24:18 | x | blocks.rb:25:8:25:8 | x | provenance | |
8+
| callbacks.rb:9:15:9:15 | x | callbacks.rb:10:12:10:12 | x | provenance | |
9+
| callbacks.rb:10:12:10:12 | x | callbacks.rb:17:15:17:15 | x | provenance | |
10+
| callbacks.rb:10:12:10:12 | x | callbacks.rb:18:15:18:15 | x | provenance | |
11+
| callbacks.rb:13:20:13:20 | x | callbacks.rb:14:14:14:14 | x | provenance | |
12+
| callbacks.rb:14:14:14:14 | x | callbacks.rb:9:15:9:15 | x | provenance | |
13+
| callbacks.rb:17:15:17:15 | x | callbacks.rb:17:25:17:25 | x | provenance | |
14+
| callbacks.rb:17:31:17:38 | call to taint | callbacks.rb:13:20:13:20 | x | provenance | |
15+
| callbacks.rb:18:15:18:15 | x | callbacks.rb:18:25:18:25 | x | provenance | |
16+
| callbacks.rb:20:17:20:17 | x | callbacks.rb:21:11:21:11 | x | provenance | |
17+
| callbacks.rb:21:11:21:11 | x | callbacks.rb:28:31:28:31 | x | provenance | |
18+
| callbacks.rb:21:11:21:11 | x | callbacks.rb:29:29:29:29 | x | provenance | |
19+
| callbacks.rb:24:23:24:23 | x | callbacks.rb:25:17:25:17 | x | provenance | |
20+
| callbacks.rb:25:17:25:17 | x | callbacks.rb:20:17:20:17 | x | provenance | |
21+
| callbacks.rb:28:18:28:25 | call to taint | callbacks.rb:24:23:24:23 | x | provenance | |
22+
| callbacks.rb:28:31:28:31 | x | callbacks.rb:28:39:28:39 | x | provenance | |
23+
| callbacks.rb:29:29:29:29 | x | callbacks.rb:29:37:29:37 | x | provenance | |
824
| captured_variables.rb:9:24:9:24 | x | captured_variables.rb:11:5:11:6 | fn : [lambda] [captured x] | provenance | |
925
| captured_variables.rb:11:5:11:6 | fn : [lambda] [captured x] | captured_variables.rb:10:20:10:20 | x | provenance | |
1026
| captured_variables.rb:13:20:13:29 | call to taint | captured_variables.rb:9:24:9:24 | x | provenance | |
@@ -272,6 +288,24 @@ nodes
272288
| blocks.rb:24:3:24:11 | call to source | semmle.label | call to source |
273289
| blocks.rb:24:18:24:18 | x | semmle.label | x |
274290
| blocks.rb:25:8:25:8 | x | semmle.label | x |
291+
| callbacks.rb:9:15:9:15 | x | semmle.label | x |
292+
| callbacks.rb:10:12:10:12 | x | semmle.label | x |
293+
| callbacks.rb:13:20:13:20 | x | semmle.label | x |
294+
| callbacks.rb:14:14:14:14 | x | semmle.label | x |
295+
| callbacks.rb:17:15:17:15 | x | semmle.label | x |
296+
| callbacks.rb:17:25:17:25 | x | semmle.label | x |
297+
| callbacks.rb:17:31:17:38 | call to taint | semmle.label | call to taint |
298+
| callbacks.rb:18:15:18:15 | x | semmle.label | x |
299+
| callbacks.rb:18:25:18:25 | x | semmle.label | x |
300+
| callbacks.rb:20:17:20:17 | x | semmle.label | x |
301+
| callbacks.rb:21:11:21:11 | x | semmle.label | x |
302+
| callbacks.rb:24:23:24:23 | x | semmle.label | x |
303+
| callbacks.rb:25:17:25:17 | x | semmle.label | x |
304+
| callbacks.rb:28:18:28:25 | call to taint | semmle.label | call to taint |
305+
| callbacks.rb:28:31:28:31 | x | semmle.label | x |
306+
| callbacks.rb:28:39:28:39 | x | semmle.label | x |
307+
| callbacks.rb:29:29:29:29 | x | semmle.label | x |
308+
| callbacks.rb:29:37:29:37 | x | semmle.label | x |
275309
| captured_variables.rb:9:24:9:24 | x | semmle.label | x |
276310
| captured_variables.rb:10:20:10:20 | x | semmle.label | x |
277311
| captured_variables.rb:11:5:11:6 | fn : [lambda] [captured x] | semmle.label | fn : [lambda] [captured x] |
@@ -582,9 +616,15 @@ subpaths
582616
| instance_variables.rb:120:6:120:10 | foo16 : Foo [@field] | captured_variables.rb:60:5:62:7 | self in get_field : Foo [@field] | captured_variables.rb:61:9:61:21 | return | instance_variables.rb:120:6:120:20 | call to get_field |
583617
| instance_variables.rb:120:6:120:10 | foo16 : Foo [@field] | instance_variables.rb:13:5:15:7 | self in get_field : Foo [@field] | instance_variables.rb:14:9:14:21 | return | instance_variables.rb:120:6:120:20 | call to get_field |
584618
testFailures
619+
| callbacks.rb:18:25:18:25 | x | Unexpected result: hasValueFlow=1 |
620+
| callbacks.rb:29:37:29:37 | x | Unexpected result: hasValueFlow=2 |
585621
#select
586622
| blocks.rb:8:10:8:14 | yield ... | blocks.rb:14:12:14:20 | call to source | blocks.rb:8:10:8:14 | yield ... | $@ | blocks.rb:14:12:14:20 | call to source | call to source |
587623
| blocks.rb:25:8:25:8 | x | blocks.rb:24:3:24:11 | call to source | blocks.rb:25:8:25:8 | x | $@ | blocks.rb:24:3:24:11 | call to source | call to source |
624+
| 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 |
625+
| 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 |
626+
| 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 |
627+
| 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 |
588628
| 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 |
589629
| 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 |
590630
| 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
| blocks.rb:4:10:4:10 | r | Fixed missing result: hasValueFlow=1 |
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)