Skip to content

Commit

Permalink
gobin: ignore flags in stdlib version
Browse files Browse the repository at this point in the history
Signed-off-by: RTann <[email protected]>
  • Loading branch information
RTann committed Nov 26, 2024
1 parent 3f4919e commit ad640c4
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 5 deletions.
16 changes: 12 additions & 4 deletions gobin/exe.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,11 @@ func toPackages(ctx context.Context, out *[]*claircore.Package, p string, r io.R
// TODO(hank) The "go version" is documented as the toolchain that produced
// the binary, which may be distinct from the version of the stdlib used?
// Need to investigate.
runtimeVer, err := ParseVersion(strings.TrimPrefix(bi.GoVersion, "go"))
// GoVersion only documents "go1.19.2" as an example, but something like
// "go1.20.12 X:strictfipsruntime" has been seen in the wild, hence the call
// to [strings.Cut]. This is necessary for accurate vulnerability matching.
goVer, _, _ := strings.Cut(strings.TrimPrefix(bi.GoVersion, "go"), " ")
runtimeVer, err := ParseVersion(goVer)
switch {
case errors.Is(err, nil):
case errors.Is(err, ErrInvalidSemVer):
Expand All @@ -64,9 +68,13 @@ func toPackages(ctx context.Context, out *[]*claircore.Package, p string, r io.R
}

*out = append(*out, &claircore.Package{
Kind: claircore.BINARY,
Name: "stdlib",
Version: bi.GoVersion,
Kind: claircore.BINARY,
Name: "stdlib",
// This was previously bi.GoVersion,
// but it must be changed to ensure an entry
// with the fixed NormalizedVersion is added to the
// package table without requiring a migration.
Version: goVer,
PackageDB: pkgdb,
Filepath: p,
NormalizedVersion: runtimeVer,
Expand Down
2 changes: 1 addition & 1 deletion gobin/gobin.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ type Detector struct{}

const (
detectorName = `gobin`
detectorVersion = `5`
detectorVersion = `6`
detectorKind = `package`
)

Expand Down

0 comments on commit ad640c4

Please sign in to comment.