Skip to content

Commit e40f0a7

Browse files
committed
Ruby: Fix bug in isCapturedAccess
1 parent e7acf8c commit e40f0a7

File tree

2 files changed

+5
-15
lines changed

2 files changed

+5
-15
lines changed

ruby/ql/lib/codeql/ruby/ast/internal/Variable.qll

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
private import TreeSitter
22
private import codeql.ruby.AST
3+
private import codeql.ruby.CFG
34
private import codeql.ruby.ast.internal.AST
45
private import codeql.ruby.ast.internal.Parameter
56
private import codeql.ruby.ast.internal.Pattern
@@ -364,7 +365,7 @@ private module Cached {
364365

365366
cached
366367
predicate isCapturedAccess(LocalVariableAccess access) {
367-
exists(Scope scope1, Scope scope2 |
368+
exists(Scope scope1, CfgScope scope2 |
368369
scope1 = access.getVariable().getDeclaringScope() and
369370
scope2 = access.getCfgScope() and
370371
scope1 != scope2
@@ -375,10 +376,11 @@ private module Cached {
375376
// class C
376377
// def self.m // not a captured access
377378
// end
379+
//
380+
// self.foo // not a captured access
378381
// end
379382
// ```
380-
not scope2 instanceof Toplevel or
381-
not access = any(SingletonMethod m).getObject()
383+
not scope2 instanceof Toplevel
382384
else any()
383385
)
384386
}

ruby/ql/test/library-tests/variables/varaccess.expected

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -617,30 +617,19 @@ readAccess
617617
| ssa.rb:101:5:101:10 | self |
618618
| ssa.rb:101:10:101:10 | x |
619619
captureAccess
620-
| class_variables.rb:27:3:27:11 | self |
621-
| class_variables.rb:28:3:28:7 | self |
622-
| instance_variables.rb:14:3:14:4 | self |
623-
| instance_variables.rb:21:2:21:3 | self |
624620
| instance_variables.rb:28:3:28:4 | self |
625621
| instance_variables.rb:32:12:32:13 | self |
626-
| instance_variables.rb:36:3:36:4 | self |
627622
| nested_scopes.rb:5:3:5:3 | a |
628623
| nested_scopes.rb:7:5:7:5 | a |
629624
| nested_scopes.rb:9:7:9:7 | a |
630625
| nested_scopes.rb:11:9:11:9 | a |
631626
| nested_scopes.rb:18:29:18:34 | self |
632627
| nested_scopes.rb:18:34:18:34 | a |
633-
| nested_scopes.rb:25:9:25:14 | self |
634628
| nested_scopes.rb:25:14:25:14 | a |
635-
| nested_scopes.rb:30:16:30:19 | self |
636629
| nested_scopes.rb:31:11:31:11 | a |
637-
| nested_scopes.rb:32:11:32:16 | self |
638630
| nested_scopes.rb:32:16:32:16 | a |
639-
| nested_scopes.rb:34:7:34:12 | self |
640631
| nested_scopes.rb:34:12:34:12 | a |
641-
| nested_scopes.rb:36:5:36:10 | self |
642632
| nested_scopes.rb:36:10:36:10 | a |
643-
| nested_scopes.rb:38:3:38:8 | self |
644633
| nested_scopes.rb:38:8:38:8 | a |
645634
| parameters.rb:3:4:3:9 | self |
646635
| parameters.rb:4:4:4:9 | self |
@@ -670,7 +659,6 @@ captureAccess
670659
| scopes.rb:42:2:42:4 | var |
671660
| scopes.rb:43:2:43:4 | foo |
672661
| scopes.rb:44:5:44:7 | var |
673-
| scopes.rb:45:5:45:7 | self |
674662
| scopes.rb:46:5:46:8 | var2 |
675663
| scopes.rb:47:5:47:8 | var2 |
676664
| ssa.rb:26:7:26:10 | elem |

0 commit comments

Comments
 (0)