Skip to content

Commit 4ed61c1

Browse files
committed
Ruby: add some captured-variable flow tests
1 parent b632e21 commit 4ed61c1

2 files changed

Lines changed: 71 additions & 0 deletions

File tree

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

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,17 @@
11
failures
22
edges
3+
| captured_variables.rb:1:24:1:24 | x : | captured_variables.rb:2:20:2:20 | x |
4+
| captured_variables.rb:1:24:1:24 | x : | captured_variables.rb:2:20:2:20 | x |
5+
| captured_variables.rb:5:20:5:30 | call to source : | captured_variables.rb:1:24:1:24 | x : |
6+
| captured_variables.rb:5:20:5:30 | call to source : | captured_variables.rb:1:24:1:24 | x : |
7+
| captured_variables.rb:21:33:21:33 | x : | captured_variables.rb:23:14:23:14 | x |
8+
| captured_variables.rb:21:33:21:33 | x : | captured_variables.rb:23:14:23:14 | x |
9+
| captured_variables.rb:27:29:27:39 | call to source : | captured_variables.rb:21:33:21:33 | x : |
10+
| captured_variables.rb:27:29:27:39 | call to source : | captured_variables.rb:21:33:21:33 | x : |
11+
| captured_variables.rb:32:31:32:31 | x : | captured_variables.rb:34:14:34:14 | x |
12+
| captured_variables.rb:32:31:32:31 | x : | captured_variables.rb:34:14:34:14 | x |
13+
| captured_variables.rb:38:27:38:37 | call to source : | captured_variables.rb:32:31:32:31 | x : |
14+
| captured_variables.rb:38:27:38:37 | call to source : | captured_variables.rb:32:31:32:31 | x : |
315
| instance_variables.rb:10:19:10:19 | x : | instance_variables.rb:11:18:11:18 | x : |
416
| instance_variables.rb:10:19:10:19 | x : | instance_variables.rb:11:18:11:18 | x : |
517
| instance_variables.rb:11:18:11:18 | x : | instance_variables.rb:11:9:11:14 | [post] self [@field] : |
@@ -152,6 +164,24 @@ edges
152164
| instance_variables.rb:84:6:84:10 | foo13 [@field] : | instance_variables.rb:84:6:84:20 | call to get_field |
153165
| instance_variables.rb:84:6:84:10 | foo13 [@field] : | instance_variables.rb:84:6:84:20 | call to get_field |
154166
nodes
167+
| captured_variables.rb:1:24:1:24 | x : | semmle.label | x : |
168+
| captured_variables.rb:1:24:1:24 | x : | semmle.label | x : |
169+
| captured_variables.rb:2:20:2:20 | x | semmle.label | x |
170+
| captured_variables.rb:2:20:2:20 | x | semmle.label | x |
171+
| captured_variables.rb:5:20:5:30 | call to source : | semmle.label | call to source : |
172+
| captured_variables.rb:5:20:5:30 | call to source : | semmle.label | call to source : |
173+
| captured_variables.rb:21:33:21:33 | x : | semmle.label | x : |
174+
| captured_variables.rb:21:33:21:33 | x : | semmle.label | x : |
175+
| captured_variables.rb:23:14:23:14 | x | semmle.label | x |
176+
| captured_variables.rb:23:14:23:14 | x | semmle.label | x |
177+
| captured_variables.rb:27:29:27:39 | call to source : | semmle.label | call to source : |
178+
| captured_variables.rb:27:29:27:39 | call to source : | semmle.label | call to source : |
179+
| captured_variables.rb:32:31:32:31 | x : | semmle.label | x : |
180+
| captured_variables.rb:32:31:32:31 | x : | semmle.label | x : |
181+
| captured_variables.rb:34:14:34:14 | x | semmle.label | x |
182+
| captured_variables.rb:34:14:34:14 | x | semmle.label | x |
183+
| captured_variables.rb:38:27:38:37 | call to source : | semmle.label | call to source : |
184+
| captured_variables.rb:38:27:38:37 | call to source : | semmle.label | call to source : |
155185
| instance_variables.rb:10:19:10:19 | x : | semmle.label | x : |
156186
| instance_variables.rb:10:19:10:19 | x : | semmle.label | x : |
157187
| instance_variables.rb:11:9:11:14 | [post] self [@field] : | semmle.label | [post] self [@field] : |
@@ -335,6 +365,9 @@ subpaths
335365
| instance_variables.rb:84:6:84:10 | foo13 [@field] : | instance_variables.rb:13:5:15:7 | self in get_field [@field] : | instance_variables.rb:14:9:14:21 | return : | instance_variables.rb:84:6:84:20 | call to get_field |
336366
| instance_variables.rb:84:6:84:10 | foo13 [@field] : | instance_variables.rb:13:5:15:7 | self in get_field [@field] : | instance_variables.rb:14:9:14:21 | return : | instance_variables.rb:84:6:84:20 | call to get_field |
337367
#select
368+
| captured_variables.rb:2:20:2:20 | x | captured_variables.rb:5:20:5:30 | call to source : | captured_variables.rb:2:20:2:20 | x | $@ | captured_variables.rb:5:20:5:30 | call to source : | call to source : |
369+
| captured_variables.rb:23:14:23:14 | x | captured_variables.rb:27:29:27:39 | call to source : | captured_variables.rb:23:14:23:14 | x | $@ | captured_variables.rb:27:29:27:39 | call to source : | call to source : |
370+
| captured_variables.rb:34:14:34:14 | x | captured_variables.rb:38:27:38:37 | call to source : | captured_variables.rb:34:14:34:14 | x | $@ | captured_variables.rb:38:27:38:37 | call to source : | call to source : |
338371
| instance_variables.rb:20:10:20:13 | @foo | instance_variables.rb:19:12:19:21 | call to taint : | instance_variables.rb:20:10:20:13 | @foo | $@ | instance_variables.rb:19:12:19:21 | call to taint : | call to taint : |
339372
| instance_variables.rb:25:6:25:18 | call to get_field | instance_variables.rb:24:15:24:23 | call to taint : | instance_variables.rb:25:6:25:18 | call to get_field | $@ | instance_variables.rb:24:15:24:23 | call to taint : | call to taint : |
340373
| instance_variables.rb:29:6:29:18 | call to inc_field | instance_variables.rb:28:15:28:22 | call to taint : | instance_variables.rb:29:6:29:18 | call to inc_field | $@ | instance_variables.rb:28:15:28:22 | call to taint : | call to taint : |
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
def capture_local_call x
2+
fn = -> { sink(x) } # $ hasValueFlow=1.1
3+
fn.call
4+
end
5+
capture_local_call source(1.1)
6+
7+
def capture_escape_return1 x
8+
-> {
9+
sink(x) # $ MISSING: hasValueFlow=1.2
10+
}
11+
end
12+
(capture_escape_return1 source(1.2)).call
13+
14+
def capture_escape_return2 x
15+
-> {
16+
sink(x) # $ MISSING: hasValueFlow=1.3
17+
}
18+
end
19+
Something.unknownMethod(capture_escape_return2 source(1.3))
20+
21+
def capture_escape_unknown_call x
22+
fn = -> {
23+
sink(x) # $ hasValueFlow=1.4
24+
}
25+
Something.unknownMethod(fn)
26+
end
27+
capture_escape_unknown_call source(1.4)
28+
29+
def call_it fn
30+
fn.call
31+
end
32+
def capture_escape_known_call x
33+
fn = -> {
34+
sink(x) # $ hasValueFlow=1.5
35+
}
36+
call_it fn
37+
end
38+
capture_escape_known_call source(1.5)

0 commit comments

Comments
 (0)