Skip to content

Commit e793a1e

Browse files
committed
Ruby: Add variable capture spurious flow test
1 parent 2896bfb commit e793a1e

File tree

2 files changed

+25
-0
lines changed

2 files changed

+25
-0
lines changed

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

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
testFailures
2+
| captured_variables.rb:236:14:236:14 | x | Unexpected result: hasValueFlow=19 |
23
edges
34
| blocks.rb:14:12:14:20 | call to source | blocks.rb:8:10:8:14 | yield ... | provenance | |
45
| captured_variables.rb:9:24:9:24 | x | captured_variables.rb:10:10:10:23 | -> { ... } [captured x] | provenance | |
@@ -122,6 +123,10 @@ edges
122123
| captured_variables.rb:222:11:224:5 | -> { ... } [captured x] | captured_variables.rb:222:5:222:7 | fn1 [captured x] | provenance | |
123124
| captured_variables.rb:226:5:226:7 | [post] fn1 [captured y] | captured_variables.rb:227:10:227:10 | y | provenance | |
124125
| captured_variables.rb:226:5:226:7 | fn1 [captured x] | captured_variables.rb:226:5:226:7 | [post] fn1 [captured y] | provenance | |
126+
| captured_variables.rb:233:9:233:17 | call to taint | captured_variables.rb:235:11:237:5 | -> { ... } [captured x] | provenance | |
127+
| captured_variables.rb:235:5:235:7 | fn1 [captured x] | captured_variables.rb:241:5:241:7 | fn1 [captured x] | provenance | |
128+
| captured_variables.rb:235:11:237:5 | -> { ... } [captured x] | captured_variables.rb:235:5:235:7 | fn1 [captured x] | provenance | |
129+
| captured_variables.rb:241:5:241:7 | fn1 [captured x] | captured_variables.rb:236:14:236:14 | x | provenance | |
125130
| instance_variables.rb:10:19:10:19 | x | instance_variables.rb:11:18:11:18 | x | provenance | |
126131
| instance_variables.rb:11:18:11:18 | x | instance_variables.rb:11:9:11:14 | [post] self [@field] | provenance | |
127132
| instance_variables.rb:13:5:15:7 | self in get_field [@field] | instance_variables.rb:14:16:14:21 | self [@field] | provenance | |
@@ -385,6 +390,11 @@ nodes
385390
| captured_variables.rb:226:5:226:7 | [post] fn1 [captured y] | semmle.label | [post] fn1 [captured y] |
386391
| captured_variables.rb:226:5:226:7 | fn1 [captured x] | semmle.label | fn1 [captured x] |
387392
| captured_variables.rb:227:10:227:10 | y | semmle.label | y |
393+
| captured_variables.rb:233:9:233:17 | call to taint | semmle.label | call to taint |
394+
| captured_variables.rb:235:5:235:7 | fn1 [captured x] | semmle.label | fn1 [captured x] |
395+
| captured_variables.rb:235:11:237:5 | -> { ... } [captured x] | semmle.label | -> { ... } [captured x] |
396+
| captured_variables.rb:236:14:236:14 | x | semmle.label | x |
397+
| captured_variables.rb:241:5:241:7 | fn1 [captured x] | semmle.label | fn1 [captured x] |
388398
| instance_variables.rb:10:19:10:19 | x | semmle.label | x |
389399
| instance_variables.rb:11:9:11:14 | [post] self [@field] | semmle.label | [post] self [@field] |
390400
| instance_variables.rb:11:18:11:18 | x | semmle.label | x |
@@ -595,6 +605,7 @@ subpaths
595605
| captured_variables.rb:199:10:199:10 | x | captured_variables.rb:197:9:197:17 | call to taint | captured_variables.rb:199:10:199:10 | x | $@ | captured_variables.rb:197:9:197:17 | call to taint | call to taint |
596606
| captured_variables.rb:208:14:208:14 | x | captured_variables.rb:206:13:206:21 | call to taint | captured_variables.rb:208:14:208:14 | x | $@ | captured_variables.rb:206:13:206:21 | call to taint | call to taint |
597607
| captured_variables.rb:227:10:227:10 | y | captured_variables.rb:219:9:219:17 | call to taint | captured_variables.rb:227:10:227:10 | y | $@ | captured_variables.rb:219:9:219:17 | call to taint | call to taint |
608+
| captured_variables.rb:236:14:236:14 | x | captured_variables.rb:233:9:233:17 | call to taint | captured_variables.rb:236:14:236:14 | x | $@ | captured_variables.rb:233:9:233:17 | call to taint | call to taint |
598609
| 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 |
599610
| instance_variables.rb:36:10:36:33 | call to get_field | instance_variables.rb:36:14:36:22 | call to taint | instance_variables.rb:36:10:36:33 | call to get_field | $@ | instance_variables.rb:36:14:36:22 | call to taint | call to taint |
600611
| instance_variables.rb:39:6:39:33 | call to get_field | instance_variables.rb:39:14:39:22 | call to taint | instance_variables.rb:39:6:39:33 | call to get_field | $@ | instance_variables.rb:39:14:39:22 | call to taint | call to taint |

ruby/ql/test/library-tests/dataflow/global/captured_variables.rb

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -228,3 +228,17 @@ def multi_capture
228228
end
229229

230230
multi_capture
231+
232+
def m1
233+
x = taint(19)
234+
235+
fn1 = -> {
236+
sink x
237+
}
238+
239+
x = nil
240+
241+
fn1.call()
242+
end
243+
244+
m1

0 commit comments

Comments
 (0)