Skip to content

Commit 06ce40c

Browse files
authored
Merge pull request #16561 from aschackmull/java/typeflow-effectively-private
Java: Improve dispatch through TypeFlow of effectively private calls.
2 parents 01c1acd + 70d3be0 commit 06ce40c

File tree

3 files changed

+20
-4
lines changed

3 files changed

+20
-4
lines changed
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
---
2+
category: majorAnalysis
3+
---
4+
* The precision of virtual dispatch has been improved. This increases precision in general for all data flow queries.

java/ql/lib/semmle/code/java/dataflow/TypeFlow.qll

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -63,12 +63,24 @@ private module Input implements TypeFlowInput<Location> {
6363

6464
class Type = RefType;
6565

66+
private SrcCallable viableCallable_v1(Call c) {
67+
result = viableImpl_v1(c)
68+
or
69+
c instanceof ConstructorCall and result = c.getCallee().getSourceDeclaration()
70+
}
71+
6672
/**
67-
* Holds if `arg` is an argument for the parameter `p` in a private callable.
73+
* Holds if `arg` is an argument for the parameter `p` in a sufficiently
74+
* private callable that the closed-world assumption applies.
6875
*/
6976
private predicate privateParamArg(Parameter p, Argument arg) {
70-
p.getAnArgument() = arg and
71-
p.getCallable().isPrivate()
77+
exists(SrcCallable c, Call call |
78+
c = p.getCallable() and
79+
not c.isImplicitlyPublic() and
80+
not p.isVarargs() and
81+
c = viableCallable_v1(call) and
82+
call.getArgument(pragma[only_bind_into](pragma[only_bind_out](p.getPosition()))) = arg
83+
)
7284
}
7385

7486
/**

java/ql/test/library-tests/dispatch/ViableCallable.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11

2-
class ViableCallable {
2+
public class ViableCallable {
33
public <T1, T2, T3> void Run(C1<T1, T2> x1, C1<T1[], T2> x2, T1 t1, T1[] t1s) {
44
// Viable callables: C2.M(), C3.M(), C4.M(), C5.M(), C6.M(), C7.M(), C8.M(), C9.M()
55
x1.M(t1, 8);

0 commit comments

Comments
 (0)