Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit cf4b6e5

Browse filesBrowse files
committed
Ruby: Include ancestors in type model generation
1 parent fb42dc9 commit cf4b6e5
Copy full SHA for cf4b6e5

File tree

3 files changed

+19
-0
lines changed
Filter options

3 files changed

+19
-0
lines changed

‎ruby/ql/lib/codeql/ruby/ast/Module.qll

Copy file name to clipboardExpand all lines: ruby/ql/lib/codeql/ruby/ast/Module.qll
+5Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -173,6 +173,11 @@ class Module extends TModule {
173173
result.getParentModule() = this and
174174
result.getOwnModuleName() = name
175175
}
176+
177+
/**
178+
* Holds if this is a built-in module, e.g. `Object`.
179+
*/
180+
predicate isBuiltin() { isBuiltinModule(this) }
176181
}
177182

178183
/**

‎ruby/ql/lib/codeql/ruby/ast/internal/Module.qll

Copy file name to clipboardExpand all lines: ruby/ql/lib/codeql/ruby/ast/internal/Module.qll
+3Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,9 @@ private module Cached {
4242
result = getAnAssumedGlobalNamespacePrefix(n)
4343
}
4444

45+
cached
46+
predicate isBuiltinModule(Module m) { m = TResolved(builtin()) }
47+
4548
cached
4649
Module getSuperClass(Module cls) {
4750
cls = TResolved("Object") and result = TResolved("BasicObject")

‎ruby/ql/src/queries/modeling/internal/Types.qll

Copy file name to clipboardExpand all lines: ruby/ql/src/queries/modeling/internal/Types.qll
+11Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66
private import ruby
77
private import codeql.ruby.ApiGraphs
88
private import Util as Util
9+
private import codeql.ruby.ast.Module
10+
private import codeql.ruby.ast.internal.Module
911

1012
/**
1113
* Contains predicates for generating `typeModel`s that contain typing
@@ -42,5 +44,14 @@ module Types {
4244
valueHasTypeName(node.getAValueReachingSink(), type1) and
4345
Util::pathToNode(node, type2, path, true)
4446
)
47+
or
48+
// class Type2 < Type1
49+
// class Type2; include Type1
50+
// class Type2; extend Type1
51+
exists(Module m1, Module m2 |
52+
m2.getAnImmediateAncestor() = m1 and not m2.isBuiltin() and not m1.isBuiltin()
53+
|
54+
m1.getQualifiedName() = type1 and m2.getQualifiedName() = type2 and path = ""
55+
)
4556
}
4657
}

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.