Skip to content

Commit 23447e6

Browse files
committed
Reduce size of lookupMethodOrConst
1 parent bf696df commit 23447e6

3 files changed

Lines changed: 9 additions & 181 deletions

File tree

ql/src/codeql_ruby/ast/internal/Module.qll

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -376,9 +376,17 @@ private TMethodOrExpr lookupMethodOrConst0(Module m, string name) {
376376
)
377377
}
378378

379+
private AstNode getNode(TMethodOrExpr e) { e = TMethod(result) or e = TExpr(result) }
380+
379381
private TMethodOrExpr lookupMethodOrConst(Module m, string name) {
380382
result = lookupMethodOrConst0(m, name)
381383
or
382384
not exists(lookupMethodOrConst0(m, name)) and
383-
result = lookupMethodOrConst(m.getSuperClass(), name)
385+
result = lookupMethodOrConst(m.getSuperClass(), name) and
386+
// For now, we restrict the scope of top-level declarations to their file.
387+
// This may remove some plausible targets, but also removes a lot of
388+
// implausible targets
389+
if getNode(result).getEnclosingModule() instanceof Toplevel
390+
then getNode(result).getFile() = m.getADeclaration().getFile()
391+
else any()
384392
}

ql/test/library-tests/ast/constants/constants.expected

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -40,16 +40,4 @@ lookupConst
4040
| constants.rb:12:9:13:11 | ModuleA::ModuleB::ClassC | GREETING | constants.rb:17:12:17:64 | ... + ... |
4141
| constants.rb:31:1:32:3 | ModuleA::ClassD | CONST_A | constants.rb:3:19:3:27 | "const_a" |
4242
| constants.rb:31:1:32:3 | ModuleA::ClassD | GREETING | constants.rb:17:12:17:64 | ... + ... |
43-
| file://:0:0:0:0 | Array | GREETING | constants.rb:17:12:17:64 | ... + ... |
44-
| file://:0:0:0:0 | Class | GREETING | constants.rb:17:12:17:64 | ... + ... |
45-
| file://:0:0:0:0 | Complex | GREETING | constants.rb:17:12:17:64 | ... + ... |
46-
| file://:0:0:0:0 | FalseClass | GREETING | constants.rb:17:12:17:64 | ... + ... |
47-
| file://:0:0:0:0 | Float | GREETING | constants.rb:17:12:17:64 | ... + ... |
48-
| file://:0:0:0:0 | Hash | GREETING | constants.rb:17:12:17:64 | ... + ... |
49-
| file://:0:0:0:0 | Integer | GREETING | constants.rb:17:12:17:64 | ... + ... |
50-
| file://:0:0:0:0 | Module | GREETING | constants.rb:17:12:17:64 | ... + ... |
51-
| file://:0:0:0:0 | NilClass | GREETING | constants.rb:17:12:17:64 | ... + ... |
52-
| file://:0:0:0:0 | Numeric | GREETING | constants.rb:17:12:17:64 | ... + ... |
5343
| file://:0:0:0:0 | Object | GREETING | constants.rb:17:12:17:64 | ... + ... |
54-
| file://:0:0:0:0 | Rational | GREETING | constants.rb:17:12:17:64 | ... + ... |
55-
| file://:0:0:0:0 | TrueClass | GREETING | constants.rb:17:12:17:64 | ... + ... |

0 commit comments

Comments
 (0)