From 1a1770fc06e2105fbb8a8efc7a5ac10b8fb71075 Mon Sep 17 00:00:00 2001 From: Erik Krogh Kristensen Date: Wed, 13 Oct 2021 16:20:07 +0200 Subject: [PATCH] resolve imports across qlpacks --- ql/src/codeql_ql/ast/Ast.qll | 9 ++++++++- ql/src/codeql_ql/ast/internal/Module.qll | 6 ++++-- 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/ql/src/codeql_ql/ast/Ast.qll b/ql/src/codeql_ql/ast/Ast.qll index 758c8c7418e..2f0724abb0f 100644 --- a/ql/src/codeql_ql/ast/Ast.qll +++ b/ql/src/codeql_ql/ast/Ast.qll @@ -2143,7 +2143,7 @@ module YAML { exists(YAMLEntry entry | entry.isRoot() and entry.getKey().getQualifiedName() = name and - result = entry.getValue().getValue() and + result = entry.getValue().getValue().trim() and entry.getLocation().getFile() = file ) } @@ -2190,6 +2190,13 @@ module YAML { ) } + /** + * Gets a QLPack that this QLPack depends on. + */ + QLPack getADependency() { + exists(string name | hasDependency(name, _) | result.getName().replaceAll("-", "/") = name) + } + Location getLocation() { // hacky, just pick the first node in the file. result = diff --git a/ql/src/codeql_ql/ast/internal/Module.qll b/ql/src/codeql_ql/ast/internal/Module.qll index 1443876c30d..a64ccfd0f2d 100644 --- a/ql/src/codeql_ql/ast/internal/Module.qll +++ b/ql/src/codeql_ql/ast/internal/Module.qll @@ -100,8 +100,10 @@ private predicate resolveQualifiedName(Import imp, ContainerOrModule m, int i) { exists(Container c, Container parent | // should ideally look at `qlpack.yml` files parent = imp.getLocation().getFile().getParentContainer+() and - exists(parent.getFile("qlpack.yml")) and - c.getParentContainer() = parent and + exists(YAML::QLPack pack | + pack.getFile().getParentContainer() = parent and + c.getParentContainer() = pack.getADependency*().getFile().getParentContainer() + ) and q = m.getName() | m = TFile(c)