Skip to content

Commit 47d946f

Browse files
committed
Make MaD package match any version without $ANYVERSION
Note that if the package column contains major version suffix (like "/v2") or if it ends with "$THISVERSION" (which is removed) then we don't do any version matching.
1 parent ea0db4d commit 47d946f

File tree

1 file changed

+21
-4
lines changed

1 file changed

+21
-4
lines changed

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

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -306,14 +306,31 @@ private predicate elementSpec(
306306
neutralModel(package, type, name, signature, _, _) and ext = "" and subtypes = false
307307
}
308308

309+
/**
310+
* Gets the string for the package path corresponding to `p`, if one exists.
311+
*
312+
* If `p` has `$THISVERSION` at the end then we remove that and do not attempt
313+
* to match any other versions of the same package. If `p` contains a major
314+
* version suffix (like "/v2") then we also do not attempt to match any
315+
*/
309316
bindingset[p]
310317
private string interpretPackage(string p) {
311-
exists(string r | r = "([^$]+)([./]\\$ANYVERSION(/|$)(.*))?" |
312-
if exists(p.regexpCapture(r, 4))
313-
then result = package(p.regexpCapture(r, 1), p.regexpCapture(r, 4))
314-
else result = package(p, "")
318+
exists(Package pkg | result = pkg.getPath() |
319+
exists(string thisVersion, string specifiedVersionRegex |
320+
thisVersion = "$THISVERSION" and
321+
specifiedVersionRegex = "[./]v\\d+"
322+
|
323+
if p.suffix(p.length() - thisVersion.length()) = thisVersion
324+
then result = p.prefix(p.length() - 12)
325+
else
326+
if exists(p.regexpFind(specifiedVersionRegex, 0, _))
327+
then result = p
328+
else p = pkg.getPathWithoutMajorVersionSuffix()
329+
)
315330
)
316331
or
332+
// Special case for built-in functions, which are not in any package, but
333+
// satisfy `hasQualifiedName` with the package path "".
317334
p = "" and result = ""
318335
}
319336

0 commit comments

Comments
 (0)