mirror of
https://github.com/github/codeql.git
synced 2026-04-28 18:25:24 +02:00
Merge pull request #13936 from hvitved/ruby/captured-access-fix
Ruby: Fix bug in `isCapturedAccess`
This commit is contained in:
@@ -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()
|
||||
)
|
||||
}
|
||||
|
||||
@@ -616,3 +616,62 @@ readAccess
|
||||
| ssa.rb:100:10:100:11 | b4 |
|
||||
| ssa.rb:101:5:101:10 | self |
|
||||
| ssa.rb:101:10:101:10 | x |
|
||||
captureAccess
|
||||
| instance_variables.rb:28:3:28:4 | self |
|
||||
| instance_variables.rb:32:12:32:13 | 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:14:25:14 | a |
|
||||
| nested_scopes.rb:31:11:31:11 | a |
|
||||
| nested_scopes.rb:32:16:32:16 | a |
|
||||
| nested_scopes.rb:34:12:34:12 | a |
|
||||
| nested_scopes.rb:36:10:36:10 | a |
|
||||
| nested_scopes.rb:38:8:38:8 | a |
|
||||
| parameters.rb:3:4:3:9 | self |
|
||||
| parameters.rb:4:4:4:9 | self |
|
||||
| parameters.rb:17:5:17:28 | self |
|
||||
| parameters.rb:54:19:54:19 | x |
|
||||
| parameters.rb:55:4:55:9 | self |
|
||||
| parameters.rb:55:9:55:9 | x |
|
||||
| parameters.rb:56:4:56:9 | self |
|
||||
| scopes.rb:3:4:3:9 | self |
|
||||
| scopes.rb:3:9:3:9 | self |
|
||||
| scopes.rb:5:4:5:9 | self |
|
||||
| scopes.rb:10:4:10:9 | self |
|
||||
| scopes.rb:10:9:10:9 | a |
|
||||
| scopes.rb:11:4:11:4 | a |
|
||||
| scopes.rb:11:4:11:4 | a |
|
||||
| scopes.rb:12:4:12:9 | self |
|
||||
| scopes.rb:12:9:12:9 | a |
|
||||
| scopes.rb:13:4:13:4 | a |
|
||||
| scopes.rb:14:4:14:9 | self |
|
||||
| scopes.rb:14:9:14:9 | a |
|
||||
| scopes.rb:15:4:15:9 | self |
|
||||
| scopes.rb:16:4:16:9 | self |
|
||||
| scopes.rb:17:4:17:9 | self |
|
||||
| scopes.rb:29:3:29:3 | x |
|
||||
| scopes.rb:32:3:32:3 | x |
|
||||
| scopes.rb:35:3:35:3 | x |
|
||||
| scopes.rb:42:2:42:4 | var |
|
||||
| scopes.rb:43:2:43:4 | foo |
|
||||
| scopes.rb:44:5:44:7 | var |
|
||||
| scopes.rb:46:5:46:8 | var2 |
|
||||
| scopes.rb:47:5:47:8 | var2 |
|
||||
| ssa.rb:26:7:26:10 | elem |
|
||||
| ssa.rb:27:5:27:13 | self |
|
||||
| ssa.rb:27:10:27:13 | elem |
|
||||
| ssa.rb:34:5:34:10 | self |
|
||||
| ssa.rb:67:5:67:10 | self |
|
||||
| ssa.rb:68:5:68:17 | self |
|
||||
| ssa.rb:68:10:68:17 | captured |
|
||||
| ssa.rb:69:5:69:12 | captured |
|
||||
| ssa.rb:69:5:69:12 | captured |
|
||||
| ssa.rb:77:6:77:23 | self |
|
||||
| ssa.rb:77:15:77:22 | captured |
|
||||
| ssa.rb:84:6:86:8 | self |
|
||||
| ssa.rb:85:10:85:22 | self |
|
||||
| ssa.rb:85:15:85:22 | captured |
|
||||
|
||||
@@ -12,3 +12,5 @@ query predicate explicitWrite(VariableWriteAccess write, AstNode assignment) {
|
||||
query predicate implicitWrite(VariableWriteAccess write) { write.isImplicitWrite() }
|
||||
|
||||
query predicate readAccess(VariableReadAccess read) { any() }
|
||||
|
||||
query predicate captureAccess(LocalVariableAccess access) { access.isCapturedAccess() }
|
||||
|
||||
Reference in New Issue
Block a user