Skip to content

Commit 37455ec

Browse files
committed
Java: Replace ratpack test fix with general heuristic summary.
1 parent c599031 commit 37455ec

File tree

3 files changed

+44
-1
lines changed

3 files changed

+44
-1
lines changed

java/ql/lib/ext/ratpack.exec.model.yml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ extensions:
33
pack: codeql/java-all
44
extensible: summaryModel
55
data:
6-
- ["ratpack.exec", "Operation", True, "of", "(Block)", "", "Argument[0]", "Argument[0].Parameter[this]", "value", "manual"]
76
- ["ratpack.exec", "Promise", True, "apply", "", "", "Argument[this].Element", "Argument[0].Parameter[0].Element", "value", "manual"]
87
- ["ratpack.exec", "Promise", True, "apply", "", "", "Argument[0].ReturnValue.Element", "ReturnValue.Element", "value", "manual"]
98
- ["ratpack.exec", "Promise", True, "blockingMap", "", "", "Argument[this].Element", "Argument[0].Parameter[0]", "value", "manual"]

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,7 @@ abstract class SyntheticCallable extends string {
101101
* A module for importing frameworks that define synthetic callables.
102102
*/
103103
private module SyntheticCallables {
104+
private import semmle.code.java.dispatch.WrappedInvocation
104105
private import semmle.code.java.frameworks.android.Intent
105106
private import semmle.code.java.frameworks.Stream
106107
}
@@ -170,6 +171,8 @@ class SummarizedCallableBase extends TSummarizedCallableBase {
170171
}
171172
}
172173

174+
class Provenance = Impl::Public::Provenance;
175+
173176
class SummarizedCallable = Impl::Public::SummarizedCallable;
174177

175178
class NeutralCallable = Impl::Public::NeutralCallable;

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

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,3 +58,44 @@ Method getRunnerTarget(MethodAccess ma) {
5858
result.overridesOrInstantiates*(runmethod)
5959
)
6060
}
61+
62+
import semmle.code.java.dataflow.FlowSummary
63+
import semmle.code.java.dataflow.internal.FlowSummaryImplSpecific as ImplSpecific
64+
65+
private predicate hasExternalSummary(Callable c) {
66+
exists(SummarizedCallableBase scb | scb.asCallable() = c |
67+
ImplSpecific::summaryElement(scb, _, _, _, _)
68+
)
69+
}
70+
71+
private predicate mayInvokeCallback(SrcMethod m, int n) {
72+
m.getParameterType(n).(RefType).getSourceDeclaration() instanceof FunctionalInterface and
73+
(not m.fromSource() or m.isNative() or m.getFile().getAbsolutePath().matches("%/test/stubs/%")) and
74+
not hasExternalSummary(m)
75+
}
76+
77+
private class SummarizedCallableWithCallback extends SummarizedCallable {
78+
private int pos;
79+
80+
SummarizedCallableWithCallback() { mayInvokeCallback(this.asCallable(), pos) }
81+
82+
override predicate propagatesFlow(
83+
SummaryComponentStack input, SummaryComponentStack output, boolean preservesValue
84+
) {
85+
input = SummaryComponentStack::argument(pos) and
86+
output = SummaryComponentStack::push(SummaryComponent::parameter(-1), input) and
87+
preservesValue = true
88+
}
89+
90+
override predicate hasProvenance(Provenance provenance) { provenance = "hq-generated" }
91+
}
92+
93+
private class RequiredComponentStackForCallback extends RequiredSummaryComponentStack {
94+
override predicate required(SummaryComponent head, SummaryComponentStack tail) {
95+
exists(int pos |
96+
mayInvokeCallback(_, pos) and
97+
head = SummaryComponent::parameter(-1) and
98+
tail = SummaryComponentStack::argument(pos)
99+
)
100+
}
101+
}

0 commit comments

Comments
 (0)