Skip to content

Commit 6a047d6

Browse files
committed
Java: Re-factor provenance related predicates for summarized callable.
1 parent ea173f9 commit 6a047d6

File tree

2 files changed

+23
-36
lines changed

2 files changed

+23
-36
lines changed

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

Lines changed: 13 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -66,13 +66,6 @@ DataFlowType getSyntheticGlobalType(SummaryComponent::SyntheticGlobal sg) {
6666
result instanceof TypeObject
6767
}
6868

69-
bindingset[provenance]
70-
private boolean isGenerated(string provenance) {
71-
provenance = "generated" and result = true
72-
or
73-
provenance != "generated" and result = false
74-
}
75-
7669
private predicate relatedArgSpec(Callable c, string spec) {
7770
exists(
7871
string namespace, string type, boolean subtypes, string name, string signature, string ext
@@ -138,19 +131,17 @@ private predicate correspondingKotlinParameterDefaultsArgSpec(
138131

139132
/**
140133
* Holds if an external flow summary exists for `c` with input specification
141-
* `input`, output specification `output`, kind `kind`, and a flag `generated`
142-
* stating whether the summary is autogenerated.
134+
* `input`, output specification `output`, kind `kind`, and provenance `provenance`.
143135
*/
144136
predicate summaryElement(
145-
SummarizedCallableBase c, string input, string output, string kind, boolean generated
137+
SummarizedCallableBase c, string input, string output, string kind, string provenance
146138
) {
147139
exists(
148140
string namespace, string type, boolean subtypes, string name, string signature, string ext,
149-
string provenance, string originalInput, string originalOutput, Callable baseCallable
141+
string originalInput, string originalOutput, Callable baseCallable
150142
|
151143
summaryModel(namespace, type, subtypes, name, signature, ext, originalInput, originalOutput,
152144
kind, provenance) and
153-
generated = isGenerated(provenance) and
154145
baseCallable = interpretElement(namespace, type, subtypes, name, signature, ext) and
155146
(
156147
c.asCallable() = baseCallable and input = originalInput and output = originalOutput
@@ -163,13 +154,12 @@ predicate summaryElement(
163154
}
164155

165156
/**
166-
* Holds if a neutral model exists for `c`, which means that there is no
167-
* flow through `c`. The flag `generated` states whether the model is autogenerated.
157+
* Holds if a neutral model exists for `c` with provenance `provenance`,
158+
* which means that there is no flow through `c`.
168159
*/
169-
predicate neutralElement(SummarizedCallableBase c, boolean generated) {
170-
exists(string namespace, string type, string name, string signature, string provenance |
160+
predicate neutralElement(SummarizedCallableBase c, string provenance) {
161+
exists(string namespace, string type, string name, string signature |
171162
neutralModel(namespace, type, name, signature, provenance) and
172-
generated = isGenerated(provenance) and
173163
c.asCallable() = interpretElement(namespace, type, false, name, signature, "")
174164
)
175165
}
@@ -222,16 +212,14 @@ class SourceOrSinkElement = Top;
222212

223213
/**
224214
* Holds if an external source specification exists for `e` with output specification
225-
* `output`, kind `kind`, and a flag `generated` stating whether the source specification is
226-
* autogenerated.
215+
* `output`, kind `kind`, and provenance `provenance`.
227216
*/
228-
predicate sourceElement(SourceOrSinkElement e, string output, string kind, boolean generated) {
217+
predicate sourceElement(SourceOrSinkElement e, string output, string kind, string provenance) {
229218
exists(
230219
string namespace, string type, boolean subtypes, string name, string signature, string ext,
231-
string provenance, SourceOrSinkElement baseSource, string originalOutput
220+
SourceOrSinkElement baseSource, string originalOutput
232221
|
233222
sourceModel(namespace, type, subtypes, name, signature, ext, originalOutput, kind, provenance) and
234-
generated = isGenerated(provenance) and
235223
baseSource = interpretElement(namespace, type, subtypes, name, signature, ext) and
236224
(
237225
e = baseSource and output = originalOutput
@@ -243,16 +231,14 @@ predicate sourceElement(SourceOrSinkElement e, string output, string kind, boole
243231

244232
/**
245233
* Holds if an external sink specification exists for `e` with input specification
246-
* `input`, kind `kind` and a flag `generated` stating whether the sink specification is
247-
* autogenerated.
234+
* `input`, kind `kind` and provenance `provenance`.
248235
*/
249-
predicate sinkElement(SourceOrSinkElement e, string input, string kind, boolean generated) {
236+
predicate sinkElement(SourceOrSinkElement e, string input, string kind, string provenance) {
250237
exists(
251238
string namespace, string type, boolean subtypes, string name, string signature, string ext,
252-
string provenance, SourceOrSinkElement baseSink, string originalInput
239+
SourceOrSinkElement baseSink, string originalInput
253240
|
254241
sinkModel(namespace, type, subtypes, name, signature, ext, originalInput, kind, provenance) and
255-
generated = isGenerated(provenance) and
256242
baseSink = interpretElement(namespace, type, subtypes, name, signature, ext) and
257243
(
258244
e = baseSink and originalInput = input

java/ql/src/Metrics/Summaries/GeneratedVsManualCoverage.ql

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -26,15 +26,16 @@ private int getNumMadModeledApis(string package, string provenance) {
2626
sc.isAutoGenerated() and
2727
provenance = "generated"
2828
or
29-
// "manual-only"
30-
sc.hasProvenance(false) and
31-
not sc.hasProvenance(true) and
32-
provenance = "manual"
33-
or
34-
// "both"
35-
sc.hasProvenance(false) and
36-
sc.hasProvenance(true) and
37-
provenance = "both"
29+
sc.isManual() and
30+
(
31+
if sc.hasProvenance("generated")
32+
then
33+
// "both"
34+
provenance = "both"
35+
else
36+
// "manual-only"
37+
provenance = "manual"
38+
)
3839
)
3940
)
4041
}

0 commit comments

Comments
 (0)