From bd86ffb35b638f7c5ee7e88965cc162dbfa243db Mon Sep 17 00:00:00 2001 From: Erik Krogh Kristensen Date: Sat, 29 May 2021 19:20:55 +0000 Subject: [PATCH] fix the arity of predicate aliases --- ql/src/codeql_ql/ast/Ast.qll | 9 ++++++++- ql/src/codeql_ql/ast/internal/Predicate.qll | 1 + ql/test/callgraph/Foo.qll | 16 ++++++++++++++++ ql/test/callgraph/callgraph.expected | 4 ++++ 4 files changed, 29 insertions(+), 1 deletion(-) diff --git a/ql/src/codeql_ql/ast/Ast.qll b/ql/src/codeql_ql/ast/Ast.qll index d682d05f0ee..418e4102d72 100644 --- a/ql/src/codeql_ql/ast/Ast.qll +++ b/ql/src/codeql_ql/ast/Ast.qll @@ -154,7 +154,14 @@ class Predicate extends TPredicate, AstNode { /** * Gets the number of parameters. */ - int getArity() { result = count(getParameter(_)) } + int getArity() { + not this.(ClasslessPredicate).getAlias() instanceof PredicateExpr and + result = count(getParameter(_)) + or + exists(PredicateExpr alias | alias = this.(ClasslessPredicate).getAlias() | + result = alias.getArity() + ) + } /** * Gets the return type (if any) of the predicate. diff --git a/ql/src/codeql_ql/ast/internal/Predicate.qll b/ql/src/codeql_ql/ast/internal/Predicate.qll index 96e4b5e5dec..5c1fc61a961 100644 --- a/ql/src/codeql_ql/ast/internal/Predicate.qll +++ b/ql/src/codeql_ql/ast/internal/Predicate.qll @@ -240,6 +240,7 @@ module PredConsistency { query predicate noResolveCall(Call c) { not resolveCall(c, _) and not c instanceof NoneCall and + not c instanceof AnyCall and not c.getLocation().getFile().getAbsolutePath().regexpMatch(".*/(test|examples)/.*") } diff --git a/ql/test/callgraph/Foo.qll b/ql/test/callgraph/Foo.qll index e76d6c18bb2..d9a00db69bc 100644 --- a/ql/test/callgraph/Foo.qll +++ b/ql/test/callgraph/Foo.qll @@ -15,3 +15,19 @@ class Sub extends Foo { } query predicate test2() { any(Foo f).bar() } + +module Aliases { + predicate myThing2(int i, int j) { i = 2 and j = 3 } + + predicate myThing0() { any() } + + predicate alias0 = myThing0/0; + + predicate alias2 = myThing2/2; + + query predicate test3() { + alias2(3, 4) // doesn't work. + or + alias0() // <- works + } +} diff --git a/ql/test/callgraph/callgraph.expected b/ql/test/callgraph/callgraph.expected index b3fc75af731..b760eff532c 100644 --- a/ql/test/callgraph/callgraph.expected +++ b/ql/test/callgraph/callgraph.expected @@ -2,3 +2,7 @@ | Foo.qll:10:21:10:25 | PredicateCall | Foo.qll:8:3:8:28 | ClassPredicate | | Foo.qll:14:30:14:40 | MemberCall | Foo.qll:10:3:10:27 | ClassPredicate | | Foo.qll:17:27:17:42 | MemberCall | Foo.qll:8:3:8:28 | ClassPredicate | +| Foo.qll:29:5:29:16 | PredicateCall | Foo.qll:20:3:20:54 | myThing2 | +| Foo.qll:29:5:29:16 | PredicateCall | Foo.qll:26:3:26:32 | alias2 | +| Foo.qll:31:5:31:12 | PredicateCall | Foo.qll:22:3:22:32 | myThing0 | +| Foo.qll:31:5:31:12 | PredicateCall | Foo.qll:24:3:24:32 | alias0 |