Skip to content

Commit 18b99ff

Browse files
authored
Merge pull request #17284 from owen-mc/go/fix-frameworks-coverage
Go: Try to fix packages in frameworks coverage
2 parents 3dce56b + 2edadbf commit 18b99ff

File tree

1 file changed

+27
-11
lines changed

1 file changed

+27
-11
lines changed

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

+27-11
Original file line numberDiff line numberDiff line change
@@ -213,16 +213,30 @@ predicate interpretModelForTest(QlBuiltins::ExtensionId madId, string model) {
213213
)
214214
}
215215

216+
bindingset[p]
217+
private string cleanPackage(string p) {
218+
exists(string noPrefix |
219+
p = fixedVersionPrefix() + noPrefix
220+
or
221+
not p = fixedVersionPrefix() + any(string s) and
222+
noPrefix = p
223+
|
224+
result = noPrefix.regexpReplaceAll(majorVersionSuffixRegex(), "")
225+
)
226+
}
227+
216228
private predicate relevantPackage(string package) {
217-
sourceModel(package, _, _, _, _, _, _, _, _, _) or
218-
sinkModel(package, _, _, _, _, _, _, _, _, _) or
219-
summaryModel(package, _, _, _, _, _, _, _, _, _, _)
229+
exists(string p | package = cleanPackage(p) |
230+
sourceModel(p, _, _, _, _, _, _, _, _, _) or
231+
sinkModel(p, _, _, _, _, _, _, _, _, _) or
232+
summaryModel(p, _, _, _, _, _, _, _, _, _, _)
233+
)
220234
}
221235

222236
private predicate packageLink(string shortpkg, string longpkg) {
223237
relevantPackage(shortpkg) and
224238
relevantPackage(longpkg) and
225-
longpkg.prefix(longpkg.indexOf(".")) = shortpkg
239+
longpkg.prefix(longpkg.indexOf("/")) = shortpkg
226240
}
227241

228242
private predicate canonicalPackage(string package) {
@@ -245,26 +259,28 @@ predicate modelCoverage(string package, int pkgs, string kind, string part, int
245259
part = "source" and
246260
n =
247261
strictcount(string subpkg, string type, boolean subtypes, string name, string signature,
248-
string ext, string output, string provenance |
262+
string ext, string output, string provenance, string x |
249263
canonicalPkgLink(package, subpkg) and
250-
sourceModel(subpkg, type, subtypes, name, signature, ext, output, kind, provenance, _)
264+
subpkg = cleanPackage(x) and
265+
sourceModel(x, type, subtypes, name, signature, ext, output, kind, provenance, _)
251266
)
252267
or
253268
part = "sink" and
254269
n =
255270
strictcount(string subpkg, string type, boolean subtypes, string name, string signature,
256-
string ext, string input, string provenance |
271+
string ext, string input, string provenance, string x |
257272
canonicalPkgLink(package, subpkg) and
258-
sinkModel(subpkg, type, subtypes, name, signature, ext, input, kind, provenance, _)
273+
subpkg = cleanPackage(x) and
274+
sinkModel(x, type, subtypes, name, signature, ext, input, kind, provenance, _)
259275
)
260276
or
261277
part = "summary" and
262278
n =
263279
strictcount(string subpkg, string type, boolean subtypes, string name, string signature,
264-
string ext, string input, string output, string provenance |
280+
string ext, string input, string output, string provenance, string x |
265281
canonicalPkgLink(package, subpkg) and
266-
summaryModel(subpkg, type, subtypes, name, signature, ext, input, output, kind, provenance,
267-
_)
282+
subpkg = cleanPackage(x) and
283+
summaryModel(x, type, subtypes, name, signature, ext, input, output, kind, provenance, _)
268284
)
269285
)
270286
}

0 commit comments

Comments
 (0)