Skip to content

Commit d63f4bf

Browse files
authored
Merge pull request #7615 from erik-krogh/super-charpred
QL: support this.method() calls in the charpred that references non-extending supertypes
2 parents 065043b + a4cfb80 commit d63f4bf

File tree

3 files changed

+34
-2
lines changed

3 files changed

+34
-2
lines changed

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

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -77,8 +77,12 @@ private module Cached {
7777
p = t.getClassPredicate(mc.getMemberName(), mc.getNumberOfArguments())
7878
)
7979
or
80-
// super calls
81-
exists(Super sup, ClassType type, Type supertype |
80+
// super calls - and `this.method()` calls in charpreds. (Basically: in charpreds there is no difference between super and this.)
81+
exists(AstNode sup, ClassType type, Type supertype |
82+
sup instanceof Super
83+
or
84+
sup.(ThisAccess).getEnclosingPredicate() instanceof CharPred
85+
|
8286
mc.getBase() = sup and
8387
sup.getEnclosingPredicate().getParent().(Class).getType() = type and
8488
supertype in [type.getASuperType(), type.getAnInstanceofType()] and

ql/ql/test/callgraph/Bar.qll

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,3 +7,28 @@ module Firebase {
77

88
int snapshot() { result = 2 }
99
}
10+
11+
class Foo extends int {
12+
Foo() { this = 1 or this = 2 }
13+
}
14+
15+
class Function extends int {
16+
Function() { this = 1 }
17+
18+
bindingset[i]
19+
int getParameter(int i) { result = i * this }
20+
}
21+
22+
class Bar extends Foo instanceof Function {
23+
Bar() {
24+
exists(super.getParameter(0))
25+
or
26+
exists(this.getParameter(0)) // <- we support this, until it's clear whether it's a compile error or not
27+
}
28+
29+
predicate bar() {
30+
exists(super.getParameter(0))
31+
// or
32+
// exists(this.getParameter(0)) // <- this is definitely a compile error
33+
}
34+
}

ql/ql/test/callgraph/callgraph.expected

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
getTarget
22
| Bar.qll:5:38:5:47 | PredicateCall | Bar.qll:8:3:8:31 | ClasslessPredicate snapshot |
3+
| Bar.qll:24:12:24:32 | MemberCall | Bar.qll:19:3:19:47 | ClassPredicate getParameter |
4+
| Bar.qll:26:12:26:31 | MemberCall | Bar.qll:19:3:19:47 | ClassPredicate getParameter |
5+
| Bar.qll:30:12:30:32 | MemberCall | Bar.qll:19:3:19:47 | ClassPredicate getParameter |
36
| Baz.qll:8:18:8:44 | MemberCall | Baz.qll:4:3:4:37 | ClassPredicate getImportedPath |
47
| Foo.qll:5:26:5:30 | PredicateCall | Foo.qll:3:1:3:26 | ClasslessPredicate foo |
58
| Foo.qll:10:21:10:25 | PredicateCall | Foo.qll:8:3:8:28 | ClassPredicate bar |

0 commit comments

Comments
 (0)