Skip to content

Commit 80a4197

Browse files
committed
Swift: Re-factor provenance related predicates for summarized callable.
1 parent c01361a commit 80a4197

File tree

2 files changed

+24
-28
lines changed

2 files changed

+24
-28
lines changed

swift/ql/lib/codeql/swift/dataflow/ExternalFlow.qll

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,7 @@ predicate summaryModel(string row) { any(SummaryModelCsv s).row(row) }
135135
/** Holds if a source model exists for the given parameters. */
136136
predicate sourceModel(
137137
string namespace, string type, boolean subtypes, string name, string signature, string ext,
138-
string output, string kind, boolean generated
138+
string output, string kind, string provenance
139139
) {
140140
exists(string row |
141141
sourceModel(row) and
@@ -149,13 +149,13 @@ predicate sourceModel(
149149
row.splitAt(";", 6) = output and
150150
row.splitAt(";", 7) = kind
151151
) and
152-
generated = false
152+
provenance = "manual"
153153
}
154154

155155
/** Holds if a sink model exists for the given parameters. */
156156
predicate sinkModel(
157157
string namespace, string type, boolean subtypes, string name, string signature, string ext,
158-
string input, string kind, boolean generated
158+
string input, string kind, string provenance
159159
) {
160160
exists(string row |
161161
sinkModel(row) and
@@ -169,13 +169,13 @@ predicate sinkModel(
169169
row.splitAt(";", 6) = input and
170170
row.splitAt(";", 7) = kind
171171
) and
172-
generated = false
172+
provenance = "manual"
173173
}
174174

175175
/** Holds if a summary model exists for the given parameters. */
176176
predicate summaryModel(
177177
string namespace, string type, boolean subtypes, string name, string signature, string ext,
178-
string input, string output, string kind, boolean generated
178+
string input, string output, string kind, string provenance
179179
) {
180180
exists(string row |
181181
summaryModel(row) and
@@ -190,7 +190,7 @@ predicate summaryModel(
190190
row.splitAt(";", 7) = output and
191191
row.splitAt(";", 8) = kind
192192
) and
193-
generated = false
193+
provenance = "manual"
194194
}
195195

196196
private predicate relevantNamespace(string namespace) {
@@ -224,25 +224,25 @@ predicate modelCoverage(string namespace, int namespaces, string kind, string pa
224224
part = "source" and
225225
n =
226226
strictcount(string subns, string type, boolean subtypes, string name, string signature,
227-
string ext, string output, boolean generated |
227+
string ext, string output, string provenance |
228228
canonicalNamespaceLink(namespace, subns) and
229-
sourceModel(subns, type, subtypes, name, signature, ext, output, kind, generated)
229+
sourceModel(subns, type, subtypes, name, signature, ext, output, kind, provenance)
230230
)
231231
or
232232
part = "sink" and
233233
n =
234234
strictcount(string subns, string type, boolean subtypes, string name, string signature,
235-
string ext, string input, boolean generated |
235+
string ext, string input, string provenance |
236236
canonicalNamespaceLink(namespace, subns) and
237-
sinkModel(subns, type, subtypes, name, signature, ext, input, kind, generated)
237+
sinkModel(subns, type, subtypes, name, signature, ext, input, kind, provenance)
238238
)
239239
or
240240
part = "summary" and
241241
n =
242242
strictcount(string subns, string type, boolean subtypes, string name, string signature,
243-
string ext, string input, string output, boolean generated |
243+
string ext, string input, string output, string provenance |
244244
canonicalNamespaceLink(namespace, subns) and
245-
summaryModel(subns, type, subtypes, name, signature, ext, input, output, kind, generated)
245+
summaryModel(subns, type, subtypes, name, signature, ext, input, output, kind, provenance)
246246
)
247247
)
248248
}

swift/ql/lib/codeql/swift/dataflow/internal/FlowSummaryImplSpecific.qll

Lines changed: 12 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -56,51 +56,47 @@ DataFlowType getSyntheticGlobalType(SummaryComponent::SyntheticGlobal sg) { any(
5656

5757
/**
5858
* Holds if an external flow summary exists for `c` with input specification
59-
* `input`, output specification `output`, kind `kind`, and a flag `generated`
60-
* stating whether the summary is autogenerated.
59+
* `input`, output specification `output`, kind `kind`, and provenance `provenance`.
6160
*/
6261
predicate summaryElement(
63-
AbstractFunctionDecl c, string input, string output, string kind, boolean generated
62+
AbstractFunctionDecl c, string input, string output, string kind, string provenance
6463
) {
6564
exists(
6665
string namespace, string type, boolean subtypes, string name, string signature, string ext
6766
|
68-
summaryModel(namespace, type, subtypes, name, signature, ext, input, output, kind, generated) and
67+
summaryModel(namespace, type, subtypes, name, signature, ext, input, output, kind, provenance) and
6968
c = interpretElement(namespace, type, subtypes, name, signature, ext)
7069
)
7170
}
7271

7372
/**
74-
* Holds if a neutral model exists for `c`, which means that there is no
75-
* flow through `c`. The flag `generated` states whether the neutral model is autogenerated.
76-
* Note. Neutral models have not been implemented for swift.
73+
* Holds if a neutral model exists for `c` with provenance `provenance`,
74+
* which means that there is no flow through `c`.
7775
*/
78-
predicate neutralElement(AbstractFunctionDecl c, boolean generated) { none() }
76+
predicate neutralElement(AbstractFunctionDecl c, string provenance) { none() }
7977

8078
/**
8179
* Holds if an external source specification exists for `e` with output specification
82-
* `output`, kind `kind`, and a flag `generated` stating whether the source specification is
83-
* autogenerated.
80+
* `output`, kind `kind`, and provenance `provenance`.
8481
*/
85-
predicate sourceElement(Element e, string output, string kind, boolean generated) {
82+
predicate sourceElement(Element e, string output, string kind, string provenance) {
8683
exists(
8784
string namespace, string type, boolean subtypes, string name, string signature, string ext
8885
|
89-
sourceModel(namespace, type, subtypes, name, signature, ext, output, kind, generated) and
86+
sourceModel(namespace, type, subtypes, name, signature, ext, output, kind, provenance) and
9087
e = interpretElement(namespace, type, subtypes, name, signature, ext)
9188
)
9289
}
9390

9491
/**
9592
* Holds if an external sink specification exists for `e` with input specification
96-
* `input`, kind `kind` and a flag `generated` stating whether the sink specification is
97-
* autogenerated.
93+
* `input`, kind `kind` and provenance `provenance`.
9894
*/
99-
predicate sinkElement(Element e, string input, string kind, boolean generated) {
95+
predicate sinkElement(Element e, string input, string kind, string provenance) {
10096
exists(
10197
string namespace, string type, boolean subtypes, string name, string signature, string ext
10298
|
103-
sinkModel(namespace, type, subtypes, name, signature, ext, input, kind, generated) and
99+
sinkModel(namespace, type, subtypes, name, signature, ext, input, kind, provenance) and
104100
e = interpretElement(namespace, type, subtypes, name, signature, ext)
105101
)
106102
}

0 commit comments

Comments
 (0)