Skip to content

Commit fcfee08

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

2 files changed

Lines changed: 37 additions & 3 deletions

File tree

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: 33 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -289,10 +289,40 @@ 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+
not exists(YAML::QLPack dep | dep = base.getADependency*() | exists(dep.getDBScheme()))
314+
or
315+
not exists(YAML::QLPack dep | dep = sup.getADependency*() | exists(dep.getDBScheme()))
316+
)
295317
)
318+
or
319+
// for tests, and other cases where no qlpack exists.
320+
not exists(YAML::QLPack base | te.getFile() = base.getAFileInPack())
321+
or
322+
// e.g. alias for primitives.
323+
not exists(t.getDeclaration())
324+
)
325+
)
296326
}
297327

298328
pragma[noinline]

0 commit comments

Comments
 (0)