Skip to content

Commit dbfc256

Browse files
committed
Java: Remove low-confidence dispatch to known neutrals.
1 parent 04f422e commit dbfc256

File tree

5 files changed

+12
-1
lines changed

5 files changed

+12
-1
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+
* Removed low-confidence call edges to known neutral call targets from the call graph used in data flow analysis. This includes, for example, custom `List.contains` implementations when the best inferrable type at the call site is simply `List`.

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -171,6 +171,8 @@ class SummarizedCallableBase extends TSummarizedCallableBase {
171171

172172
class SummarizedCallable = Impl::Public::SummarizedCallable;
173173

174+
class NeutralCallable = Impl::Public::NeutralCallable;
175+
174176
/**
175177
* An adapter class to add the flow summaries specified on `SyntheticCallable`
176178
* to `SummarizedCallable`.

java/ql/lib/semmle/code/java/dataflow/internal/DataFlowDispatch.qll

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@ private module DispatchImpl {
1111
private predicate hasHighConfidenceTarget(Call c) {
1212
exists(SummarizedCallable sc | sc.getACall() = c and not sc.isAutoGenerated())
1313
or
14+
exists(NeutralCallable nc | nc.getACall() = c and nc.isManual())
15+
or
1416
exists(Callable srcTgt |
1517
srcTgt = VirtualDispatch::viableCallable(c) and
1618
not VirtualDispatch::lowConfidenceDispatchTarget(c, srcTgt)

java/ql/lib/semmle/code/java/dispatch/ObjFlow.qll

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -236,6 +236,8 @@ private VirtualMethodAccess objectToString(ObjNode n) {
236236
result.getQualifier() = n.asExpr() and sink(n)
237237
}
238238

239+
predicate objectToStringCall(VirtualMethodAccess ma) { ma = objectToString(_) }
240+
239241
/**
240242
* Holds if the qualifier of the `Object.toString()` call `ma` might have type `t`.
241243
*/

java/ql/lib/semmle/code/java/dispatch/VirtualDispatch.qll

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,8 @@ private module Dispatch {
9393
exists(RefType t | qualUnionType(ma, t, false) |
9494
lowConfidenceDispatchType(t.getSourceDeclaration())
9595
)
96-
)
96+
) and
97+
not ObjFlow::objectToStringCall(ma)
9798
}
9899

99100
private predicate lowConfidenceDispatchType(SrcRefType t) {

0 commit comments

Comments
 (0)