Ruby: Fix bug in isCapturedAccess

This commit is contained in:
Tom Hvitved
2023-08-10 08:26:42 +02:00
parent e7acf8c3a8
commit e40f0a7350
2 changed files with 5 additions and 15 deletions

View File

@@ -1,5 +1,6 @@
private import TreeSitter
private import codeql.ruby.AST
private import codeql.ruby.CFG
private import codeql.ruby.ast.internal.AST
private import codeql.ruby.ast.internal.Parameter
private import codeql.ruby.ast.internal.Pattern
@@ -364,7 +365,7 @@ private module Cached {
cached
predicate isCapturedAccess(LocalVariableAccess access) {
exists(Scope scope1, Scope scope2 |
exists(Scope scope1, CfgScope scope2 |
scope1 = access.getVariable().getDeclaringScope() and
scope2 = access.getCfgScope() and
scope1 != scope2
@@ -375,10 +376,11 @@ private module Cached {
// class C
// def self.m // not a captured access
// end
//
// self.foo // not a captured access
// end
// ```
not scope2 instanceof Toplevel or
not access = any(SingletonMethod m).getObject()
not scope2 instanceof Toplevel
else any()
)
}

View File

@@ -617,30 +617,19 @@ readAccess
| ssa.rb:101:5:101:10 | self |
| ssa.rb:101:10:101:10 | x |
captureAccess
| class_variables.rb:27:3:27:11 | self |
| class_variables.rb:28:3:28:7 | self |
| instance_variables.rb:14:3:14:4 | self |
| instance_variables.rb:21:2:21:3 | self |
| instance_variables.rb:28:3:28:4 | self |
| instance_variables.rb:32:12:32:13 | self |
| instance_variables.rb:36:3:36:4 | self |
| nested_scopes.rb:5:3:5:3 | a |
| nested_scopes.rb:7:5:7:5 | a |
| nested_scopes.rb:9:7:9:7 | a |
| nested_scopes.rb:11:9:11:9 | a |
| nested_scopes.rb:18:29:18:34 | self |
| nested_scopes.rb:18:34:18:34 | a |
| nested_scopes.rb:25:9:25:14 | self |
| nested_scopes.rb:25:14:25:14 | a |
| nested_scopes.rb:30:16:30:19 | self |
| nested_scopes.rb:31:11:31:11 | a |
| nested_scopes.rb:32:11:32:16 | self |
| nested_scopes.rb:32:16:32:16 | a |
| nested_scopes.rb:34:7:34:12 | self |
| nested_scopes.rb:34:12:34:12 | a |
| nested_scopes.rb:36:5:36:10 | self |
| nested_scopes.rb:36:10:36:10 | a |
| nested_scopes.rb:38:3:38:8 | self |
| nested_scopes.rb:38:8:38:8 | a |
| parameters.rb:3:4:3:9 | self |
| parameters.rb:4:4:4:9 | self |
@@ -670,7 +659,6 @@ captureAccess
| scopes.rb:42:2:42:4 | var |
| scopes.rb:43:2:43:4 | foo |
| scopes.rb:44:5:44:7 | var |
| scopes.rb:45:5:45:7 | self |
| scopes.rb:46:5:46:8 | var2 |
| scopes.rb:47:5:47:8 | var2 |
| ssa.rb:26:7:26:10 | elem |