From 3b1c04b71caa1942c201467b8d03ffcc9df47ead Mon Sep 17 00:00:00 2001 From: Erik Krogh Kristensen Date: Fri, 15 Oct 2021 21:28:19 +0200 Subject: [PATCH] correctly resolve super calls in char preds --- ql/src/codeql_ql/ast/internal/Predicate.qll | 2 +- ql/test/callgraph/Baz.qll | 11 +++++++++++ ql/test/callgraph/callgraph.expected | 1 + 3 files changed, 13 insertions(+), 1 deletion(-) create mode 100644 ql/test/callgraph/Baz.qll diff --git a/ql/src/codeql_ql/ast/internal/Predicate.qll b/ql/src/codeql_ql/ast/internal/Predicate.qll index c55a9fb80d1..44715c1b0ff 100644 --- a/ql/src/codeql_ql/ast/internal/Predicate.qll +++ b/ql/src/codeql_ql/ast/internal/Predicate.qll @@ -81,7 +81,7 @@ private module Cached { // super calls exists(Super sup, ClassType type, Type supertype | mc.getBase() = sup and - sup.getEnclosingPredicate().(ClassPredicate).getParent().getType() = type and + sup.getEnclosingPredicate().getParent().(Class).getType() = type and supertype in [type.getASuperType(), type.getAnInstanceofType()] and p = supertype.getClassPredicate(mc.getMemberName(), mc.getNumberOfArguments()) ) diff --git a/ql/test/callgraph/Baz.qll b/ql/test/callgraph/Baz.qll new file mode 100644 index 00000000000..371439d8530 --- /dev/null +++ b/ql/test/callgraph/Baz.qll @@ -0,0 +1,11 @@ +class Foo extends string { + Foo() { this = "Foo" } + + string getImportedPath() { none() } +} + +class Bar extends string, Foo { + Bar() { exists(Foo.super.getImportedPath()) } + + override string getImportedPath() { none() } +} diff --git a/ql/test/callgraph/callgraph.expected b/ql/test/callgraph/callgraph.expected index d0a4a8be0da..a931da5b1ff 100644 --- a/ql/test/callgraph/callgraph.expected +++ b/ql/test/callgraph/callgraph.expected @@ -1,5 +1,6 @@ getTarget | Bar.qll:5:38:5:47 | PredicateCall | Bar.qll:8:3:8:31 | ClasslessPredicate snapshot | +| Baz.qll:8:18:8:44 | MemberCall | Baz.qll:4:3:4:37 | ClassPredicate getImportedPath | | Foo.qll:5:26:5:30 | PredicateCall | Foo.qll:3:1:3:26 | ClasslessPredicate foo | | Foo.qll:10:21:10:25 | PredicateCall | Foo.qll:8:3:8:28 | ClassPredicate bar | | Foo.qll:14:30:14:40 | MemberCall | Foo.qll:10:3:10:27 | ClassPredicate baz |