Skip to content

Commit f026aa0

Browse files
committed
Java: Adapt to changes in FlowSummaryImpl
1 parent c5f54e9 commit f026aa0

File tree

7 files changed

+33
-58
lines changed

7 files changed

+33
-58
lines changed

java/ql/lib/semmle/code/java/ConflictingAccess.qll

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ module Modification {
2323
/** Holds if the call `c` modifies a shared resource. */
2424
predicate isModifyingCall(Call c) {
2525
exists(SummarizedCallable sc, string output | sc.getACall() = c |
26-
sc.propagatesFlow(_, output, _, _) and
26+
sc.propagatesFlow(_, output, _, _, _, _) and
2727
output.matches("Argument[this]%")
2828
)
2929
}

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

Lines changed: 14 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -620,48 +620,25 @@ predicate barrierNode(Node node, string kind) { barrierNode(node, kind, _) }
620620

621621
// adapter class for converting Mad summaries to `SummarizedCallable`s
622622
private class SummarizedCallableAdapter extends SummarizedCallable {
623-
SummarizedCallableAdapter() { summaryElement(this, _, _, _, _, _, _) }
623+
string input_;
624+
string output_;
625+
string kind;
626+
Provenance p_;
627+
boolean isExact_;
628+
string model_;
624629

625-
private predicate relevantSummaryElementManual(
626-
string input, string output, string kind, string model
627-
) {
628-
exists(Provenance provenance |
629-
summaryElement(this, input, output, kind, provenance, model, _) and
630-
provenance.isManual()
631-
)
632-
}
633-
634-
private predicate relevantSummaryElementGenerated(
635-
string input, string output, string kind, string model
636-
) {
637-
exists(Provenance provenance |
638-
summaryElement(this, input, output, kind, provenance, model, _) and
639-
provenance.isGenerated()
640-
) and
641-
not exists(Provenance provenance |
642-
neutralElement(this, "summary", provenance, _) and
643-
provenance.isManual()
644-
)
645-
}
630+
SummarizedCallableAdapter() { summaryElement(this, input_, output_, kind, p_, model_, isExact_) }
646631

647632
override predicate propagatesFlow(
648-
string input, string output, boolean preservesValue, string model
633+
string input, string output, boolean preservesValue, Provenance p, boolean isExact, string model
649634
) {
650-
exists(string kind |
651-
this.relevantSummaryElementManual(input, output, kind, model)
652-
or
653-
not this.relevantSummaryElementManual(_, _, _, _) and
654-
this.relevantSummaryElementGenerated(input, output, kind, model)
655-
|
656-
if kind = "value" then preservesValue = true else preservesValue = false
657-
)
635+
input = input_ and
636+
output = output_ and
637+
(if kind = "value" then preservesValue = true else preservesValue = false) and
638+
p = p_ and
639+
isExact = isExact_ and
640+
model = model_
658641
}
659-
660-
override predicate hasProvenance(Provenance provenance) {
661-
summaryElement(this, _, _, _, provenance, _, _)
662-
}
663-
664-
override predicate hasExactModel() { summaryElement(this, _, _, _, _, _, true) }
665642
}
666643

667644
final class SinkCallable = SinkModelCallable;

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -129,16 +129,16 @@ class SummarizedCallable = Impl::Public::SummarizedCallable;
129129
*/
130130
private class SummarizedSyntheticCallableAdapter extends SummarizedCallable, TSyntheticCallable {
131131
override predicate propagatesFlow(
132-
string input, string output, boolean preservesValue, string model
132+
string input, string output, boolean preservesValue, Provenance p, boolean isExact, string model
133133
) {
134134
exists(SyntheticCallable sc |
135135
sc = this.asSyntheticCallable() and
136136
sc.propagatesFlow(input, output, preservesValue) and
137+
p = "manual" and
138+
isExact = true and
137139
model = sc
138140
)
139141
}
140-
141-
override predicate hasExactModel() { any() }
142142
}
143143

144144
deprecated class RequiredSummaryComponentStack = Impl::Private::RequiredSummaryComponentStack;

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

Lines changed: 9 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,11 @@ private import semmle.code.java.dispatch.internal.Unification
1212

1313
private module DispatchImpl {
1414
private predicate hasHighConfidenceTarget(Call c) {
15-
exists(Impl::Public::SummarizedCallable sc | sc.getACall() = c and not sc.applyGeneratedModel())
15+
exists(Impl::Public::SummarizedCallable sc, Impl::Public::Provenance p |
16+
sc.getACall() = c and
17+
sc.propagatesFlow(_, _, _, p, _, _) and
18+
not p.isGenerated()
19+
)
1620
or
1721
exists(Impl::Public::NeutralSummaryCallable nc | nc.getACall() = c and nc.hasManualModel())
1822
or
@@ -25,8 +29,10 @@ private module DispatchImpl {
2529
private predicate hasExactManualModel(Call c, Callable tgt) {
2630
tgt = c.getCallee().getSourceDeclaration() and
2731
(
28-
exists(Impl::Public::SummarizedCallable sc |
29-
sc.getACall() = c and sc.hasExactModel() and sc.hasManualModel()
32+
exists(Impl::Public::SummarizedCallable sc, Impl::Public::Provenance p |
33+
sc.getACall() = c and
34+
sc.propagatesFlow(_, _, _, p, true, _) and
35+
p.isManual()
3036
)
3137
or
3238
exists(Impl::Public::NeutralSummaryCallable nc |
@@ -57,16 +63,6 @@ private module DispatchImpl {
5763
exists(Call call | call = c.asCall() |
5864
result.asCallable() = sourceDispatch(call)
5965
or
60-
not (
61-
// Only use summarized callables with generated summaries in case
62-
// the static call target is not in the source code.
63-
// Note that if `applyGeneratedModel` holds it implies that there doesn't
64-
// exist a manual model.
65-
exists(Callable staticTarget | staticTarget = call.getCallee().getSourceDeclaration() |
66-
staticTarget.fromSource() and not staticTarget.isStub()
67-
) and
68-
result.asSummarizedCallable().applyGeneratedModel()
69-
) and
7066
result.asSummarizedCallable().getACall() = call
7167
)
7268
}

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,8 @@ module Input implements InputSig<Location, DataFlowImplSpecific::JavaDataFlow> {
3333

3434
class SummarizedCallableBase = FlowSummary::SummarizedCallableBase;
3535

36+
predicate allowGeneratedSummary(SummarizedCallableBase c) { not c.asCallable().fromSource() }
37+
3638
class SourceBase = Void;
3739

3840
class SinkBase = Void;

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -74,13 +74,13 @@ private class SummarizedCallableWithCallback extends SummarizedCallable {
7474
SummarizedCallableWithCallback() { mayInvokeCallback(this.asCallable(), pos) }
7575

7676
override predicate propagatesFlow(
77-
string input, string output, boolean preservesValue, string model
77+
string input, string output, boolean preservesValue, Provenance p, boolean isExact, string model
7878
) {
7979
input = "Argument[" + pos + "]" and
8080
output = "Argument[" + pos + "].Parameter[-1]" and
8181
preservesValue = true and
82+
p = "hq-generated" and
83+
isExact = true and
8284
model = "heuristic-callback"
8385
}
84-
85-
override predicate hasProvenance(Provenance provenance) { provenance = "hq-generated" }
8686
}

java/ql/src/utils/modelgenerator/internal/CaptureModels.qll

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -187,7 +187,7 @@ module SummaryModelGeneratorInput implements SummaryModelGeneratorInputSig {
187187
}
188188

189189
private predicate hasManualSummaryModel(Callable api) {
190-
api = any(FlowSummaryImpl::Public::SummarizedCallable sc | sc.applyManualModel()).asCallable() or
190+
api = any(FlowSummaryImpl::Public::SummarizedCallable sc | sc.hasManualModel()).asCallable() or
191191
api = any(FlowSummaryImpl::Public::NeutralSummaryCallable sc | sc.hasManualModel()).asCallable()
192192
}
193193

0 commit comments

Comments
 (0)