Skip to content

Commit 6622eda

Browse files
committed
Go: Re-factor provenance related predicates for summarized callable.
1 parent 6a047d6 commit 6622eda

File tree

2 files changed

+31
-39
lines changed

2 files changed

+31
-39
lines changed

go/ql/lib/semmle/go/dataflow/ExternalFlow.qll

Lines changed: 19 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -124,17 +124,10 @@ predicate sinkModel(string row) { any(SinkModelCsv s).row(row) }
124124
/** Holds if `row` is a summary model. */
125125
predicate summaryModel(string row) { any(SummaryModelCsv s).row(row) }
126126

127-
bindingset[input]
128-
private predicate getKind(string input, string kind, boolean generated) {
129-
input.splitAt(":", 0) = "generated" and kind = input.splitAt(":", 1) and generated = true
130-
or
131-
not input.matches("%:%") and kind = input and generated = false
132-
}
133-
134127
/** Holds if a source model exists for the given parameters. */
135128
predicate sourceModel(
136129
string namespace, string type, boolean subtypes, string name, string signature, string ext,
137-
string output, string kind, boolean generated
130+
string output, string kind, string provenance
138131
) {
139132
exists(string row |
140133
sourceModel(row) and
@@ -146,14 +139,15 @@ predicate sourceModel(
146139
row.splitAt(";", 4) = signature and
147140
row.splitAt(";", 5) = ext and
148141
row.splitAt(";", 6) = output and
149-
exists(string k | row.splitAt(";", 7) = k and getKind(k, kind, generated))
142+
row.splitAt(";", 7) = kind and
143+
provenance = "manual"
150144
)
151145
}
152146

153147
/** Holds if a sink model exists for the given parameters. */
154148
predicate sinkModel(
155149
string namespace, string type, boolean subtypes, string name, string signature, string ext,
156-
string input, string kind, boolean generated
150+
string input, string kind, string provenance
157151
) {
158152
exists(string row |
159153
sinkModel(row) and
@@ -165,22 +159,23 @@ predicate sinkModel(
165159
row.splitAt(";", 4) = signature and
166160
row.splitAt(";", 5) = ext and
167161
row.splitAt(";", 6) = input and
168-
exists(string k | row.splitAt(";", 7) = k and getKind(k, kind, generated))
162+
row.splitAt(";", 7) = kind and
163+
provenance = "manual"
169164
)
170165
}
171166

172167
/** Holds if a summary model exists for the given parameters. */
173168
predicate summaryModel(
174169
string namespace, string type, boolean subtypes, string name, string signature, string ext,
175-
string input, string output, string kind, boolean generated
170+
string input, string output, string kind, string provenance
176171
) {
177-
summaryModel(namespace, type, subtypes, name, signature, ext, input, output, kind, generated, _)
172+
summaryModel(namespace, type, subtypes, name, signature, ext, input, output, kind, provenance, _)
178173
}
179174

180175
/** Holds if a summary model `row` exists for the given parameters. */
181176
predicate summaryModel(
182177
string namespace, string type, boolean subtypes, string name, string signature, string ext,
183-
string input, string output, string kind, boolean generated, string row
178+
string input, string output, string kind, string provenance, string row
184179
) {
185180
summaryModel(row) and
186181
row.splitAt(";", 0) = namespace and
@@ -192,7 +187,8 @@ predicate summaryModel(
192187
row.splitAt(";", 5) = ext and
193188
row.splitAt(";", 6) = input and
194189
row.splitAt(";", 7) = output and
195-
exists(string k | row.splitAt(";", 8) = k and getKind(k, kind, generated))
190+
row.splitAt(";", 8) = kind and
191+
provenance = "manual"
196192
}
197193

198194
/** Holds if `package` have CSV framework coverage. */
@@ -241,25 +237,25 @@ predicate modelCoverage(string package, int pkgs, string kind, string part, int
241237
part = "source" and
242238
n =
243239
strictcount(string subpkg, string type, boolean subtypes, string name, string signature,
244-
string ext, string output, boolean generated |
240+
string ext, string output, string provenance |
245241
canonicalPackageHasASubpackage(package, subpkg) and
246-
sourceModel(subpkg, type, subtypes, name, signature, ext, output, kind, generated)
242+
sourceModel(subpkg, type, subtypes, name, signature, ext, output, kind, provenance)
247243
)
248244
or
249245
part = "sink" and
250246
n =
251247
strictcount(string subpkg, string type, boolean subtypes, string name, string signature,
252-
string ext, string input, boolean generated |
248+
string ext, string input, string provenance |
253249
canonicalPackageHasASubpackage(package, subpkg) and
254-
sinkModel(subpkg, type, subtypes, name, signature, ext, input, kind, generated)
250+
sinkModel(subpkg, type, subtypes, name, signature, ext, input, kind, provenance)
255251
)
256252
or
257253
part = "summary" and
258254
n =
259255
strictcount(string subpkg, string type, boolean subtypes, string name, string signature,
260-
string ext, string input, string output, boolean generated |
256+
string ext, string input, string output, string provenance |
261257
canonicalPackageHasASubpackage(package, subpkg) and
262-
summaryModel(subpkg, type, subtypes, name, signature, ext, input, output, kind, generated)
258+
summaryModel(subpkg, type, subtypes, name, signature, ext, input, output, kind, provenance)
263259
)
264260
)
265261
}
@@ -298,9 +294,8 @@ module CsvValidation {
298294
}
299295

300296
private string getInvalidModelKind() {
301-
exists(string row, string k, string kind | summaryModel(row) |
302-
k = row.splitAt(";", 8) and
303-
getKind(k, kind, _) and
297+
exists(string row, string kind | summaryModel(row) |
298+
kind = row.splitAt(";", 8) and
304299
not kind = ["taint", "value"] and
305300
result = "Invalid kind \"" + kind + "\" in summary model."
306301
)

go/ql/lib/semmle/go/dataflow/internal/FlowSummaryImplSpecific.qll

Lines changed: 12 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -60,26 +60,25 @@ DataFlowType getSyntheticGlobalType(SummaryComponent::SyntheticGlobal sg) { any(
6060

6161
/**
6262
* Holds if an external flow summary exists for `c` with input specification
63-
* `input`, output specification `output`, kind `kind`, and a flag `generated`
64-
* stating whether the summary is autogenerated.
63+
* `input`, output specification `output`, kind `kind`, and provenance `provenance`.
6564
*/
6665
predicate summaryElement(
67-
SummarizedCallableBase c, string input, string output, string kind, boolean generated
66+
SummarizedCallableBase c, string input, string output, string kind, string provenance
6867
) {
6968
exists(
7069
string namespace, string type, boolean subtypes, string name, string signature, string ext
7170
|
72-
summaryModel(namespace, type, subtypes, name, signature, ext, input, output, kind, generated) and
71+
summaryModel(namespace, type, subtypes, name, signature, ext, input, output, kind, provenance) and
7372
c.asFunction() = interpretElement(namespace, type, subtypes, name, signature, ext).asEntity()
7473
)
7574
}
7675

7776
/**
78-
* Holds if a neutral model exists for `c`, which means that there is no
79-
* flow through `c`. The flag `generated` states whether the model is autogenerated.
77+
* Holds if a neutral model exists for `c` with provenance `provenance`,
78+
* which means that there is no flow through `c`.
8079
* Note. Neutral models have not been implemented for Go.
8180
*/
82-
predicate neutralElement(SummarizedCallable c, boolean generated) { none() }
81+
predicate neutralElement(SummarizedCallable c, string provenance) { none() }
8382

8483
/** Gets the summary component for specification component `c`, if any. */
8584
bindingset[c]
@@ -152,28 +151,26 @@ class SourceOrSinkElement extends TSourceOrSinkElement {
152151

153152
/**
154153
* Holds if an external source specification exists for `e` with output specification
155-
* `output`, kind `kind`, and a flag `generated` stating whether the source specification is
156-
* autogenerated.
154+
* `output`, kind `kind`, and provenance `provenance`.
157155
*/
158-
predicate sourceElement(SourceOrSinkElement e, string output, string kind, boolean generated) {
156+
predicate sourceElement(SourceOrSinkElement e, string output, string kind, string provenance) {
159157
exists(
160158
string namespace, string type, boolean subtypes, string name, string signature, string ext
161159
|
162-
sourceModel(namespace, type, subtypes, name, signature, ext, output, kind, generated) and
160+
sourceModel(namespace, type, subtypes, name, signature, ext, output, kind, provenance) and
163161
e = interpretElement(namespace, type, subtypes, name, signature, ext)
164162
)
165163
}
166164

167165
/**
168166
* Holds if an external sink specification exists for `e` with input specification
169-
* `input`, kind `kind` and a flag `generated` stating whether the sink specification is
170-
* autogenerated.
167+
* `input`, kind `kind` and provenance `provenance`.
171168
*/
172-
predicate sinkElement(SourceOrSinkElement e, string input, string kind, boolean generated) {
169+
predicate sinkElement(SourceOrSinkElement e, string input, string kind, string provenance) {
173170
exists(
174171
string namespace, string type, boolean subtypes, string name, string signature, string ext
175172
|
176-
sinkModel(namespace, type, subtypes, name, signature, ext, input, kind, generated) and
173+
sinkModel(namespace, type, subtypes, name, signature, ext, input, kind, provenance) and
177174
e = interpretElement(namespace, type, subtypes, name, signature, ext)
178175
)
179176
}

0 commit comments

Comments
 (0)