Skip to content

Commit 7d0beea

Browse files
committed
QL: prevent some cross-talk between modules
1 parent c11d63e commit 7d0beea

File tree

2 files changed

+38
-3
lines changed

2 files changed

+38
-3
lines changed

ql/ql/src/codeql_ql/ast/Ast.qll

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,10 @@ class AstNode extends TAstNode {
2525
cached
2626
Location getLocation() { result = this.getFullLocation() } // overridden in some subclasses
2727

28+
/** Gets the file containing this AST node. */
29+
cached
30+
File getFile() { result = getFullLocation().getFile() }
31+
2832
/** Gets the location that spans the entire AST node. */
2933
cached
3034
final Location getFullLocation() {

ql/ql/src/codeql_ql/ast/internal/Type.qll

Lines changed: 34 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -289,10 +289,41 @@ predicate resolveTypeExpr(TypeExpr te, Type t) {
289289
else
290290
if primTypeName(te.getClassName())
291291
then t = TPrimitive(te.getClassName())
292-
else
293-
exists(FileOrModule m, boolean public, string clName | qualifier(te, m, public, clName) |
294-
defines(m, clName, t, public)
292+
else resolveTypeExpr2(te, t)
293+
}
294+
295+
pragma[noopt]
296+
predicate resolveTypeExpr2(TypeExpr te, Type t) {
297+
exists(FileOrModule m, boolean public, string clName |
298+
qualifier(te, m, public, clName) and
299+
defines(m, clName, t, public) and
300+
// there can be some cross-talk between modules due to collapsing parameterized modules. This should remove the worst.
301+
// require that the Type is contained in the same pack or a dependency.
302+
(
303+
exists(YAML::QLPack base, YAML::QLPack sup |
304+
te.getFile() = base.getAFileInPack() and
305+
exists(AstNode decl, File f |
306+
decl = t.getDeclaration() and
307+
f = decl.getFile() and
308+
f = sup.getAFileInPack()
309+
) and
310+
(
311+
base.getADependency*() = sup
312+
or
313+
// only interested in blocking language -> language flow, so we include if one of the packs is shared (has no dbscheme).
314+
not exists(YAML::QLPack dep | dep = base.getADependency*() | exists(dep.getDBScheme()))
315+
or
316+
not exists(YAML::QLPack dep | dep = sup.getADependency*() | exists(dep.getDBScheme()))
317+
)
295318
)
319+
or
320+
// for tests, and other cases where no qlpack exists.
321+
not exists(YAML::QLPack base | te.getFile() = base.getAFileInPack())
322+
or
323+
// e.g. alias for primitives.
324+
not exists(t.getDeclaration())
325+
)
326+
)
296327
}
297328

298329
pragma[noinline]

0 commit comments

Comments
 (0)