fix: further improve go binary classifier, including windows (#4593)

Signed-off-by: Keith Zantow <kzantow@gmail.com>
This commit is contained in:
Keith Zantow 2026-02-03 10:29:00 -05:00 committed by GitHub
parent d22139ef1a
commit add2629446
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
9 changed files with 43 additions and 4 deletions

View File

@ -48,7 +48,7 @@ catalogers:
type: BinaryPkg
- method: glob
criteria:
- '**/go'
- '**/{go,go.exe}'
packages:
- class: go-binary
name: go

View File

@ -736,6 +736,26 @@ func Test_Cataloger_PositiveCases(t *testing.T) {
Metadata: metadata("go-binary"),
},
},
{
logicalFixture: "go-version-hint/1.15w/any",
expected: pkg.Package{
Name: "go",
Version: "1.15",
PURL: "pkg:generic/go@1.15",
Locations: locations("bin/go.exe", "VERSION"),
Metadata: metadata("go-binary"),
},
},
{
logicalFixture: "go-version-hint/1.21/any",
expected: pkg.Package{
Name: "go",
Version: "1.21",
PURL: "pkg:generic/go@1.21",
Locations: locations("go", "VERSION"),
Metadata: metadata("go-binary"),
},
},
{
// note: this is for compatability with dev version of golang tip image, which resolves the issue #3681
logicalFixture: "go-version-hint/1.25/any",
@ -747,6 +767,16 @@ func Test_Cataloger_PositiveCases(t *testing.T) {
Metadata: metadata("go-binary"),
},
},
{
logicalFixture: "go-version-hint/1.25w/any",
expected: pkg.Package{
Name: "go",
Version: "1.25-d524e1e",
PURL: "pkg:generic/go@1.25-d524e1e",
Locations: locations("go.exe", "VERSION"),
Metadata: metadata("go-binary"),
},
},
{
// note: this is testing BUSYBOX which is typically through a link to "[" (in this case a symlink but in
// practice this is often a hard link).

View File

@ -70,14 +70,16 @@ func DefaultClassifiers() []binutils.Classifier {
},
{
Class: "go-binary",
FileGlob: "**/go",
FileGlob: "**/{go,go.exe}",
EvidenceMatcher: binutils.MatchAny(
m.FileContentsVersionMatcher(
`(?m)go(?P<version>[0-9]+\.[0-9]+(\.[0-9]+|beta[0-9]+|alpha[0-9]+|rc[0-9]+)?)\x00`),
binutils.SupportingEvidenceMatcher("VERSION*",
m.FileContentsVersionMatcher(
`(?m)go(?P<version>[0-9]+\.[0-9]+(\.[0-9]+|beta[0-9]+|alpha[0-9]+|rc[0-9]+|-[_0-9a-z]+)?)\s`)),
binutils.SupportingEvidenceMatcher("../VERSION*",
m.FileContentsVersionMatcher(
`(?m)go(?P<version>[0-9]+\.[0-9]+(\.[0-9]+|beta[0-9]+|alpha[0-9]+|rc[0-9]+|-[_0-9a-z]+)?)\s`),
),
`(?m)go(?P<version>[0-9]+\.[0-9]+(\.[0-9]+|beta[0-9]+|alpha[0-9]+|rc[0-9]+|-[_0-9a-z]+)?)\s`)),
),
Package: "go",
PURL: mustPURL("pkg:generic/go@version"),

View File

@ -0,0 +1 @@
no version in this binary

View File

@ -0,0 +1 @@
no version in this binary

View File

@ -0,0 +1,2 @@
devel go1.25-d524e1e Sun Feb 16 07:23:13 2025 -0800
3devel go1.25-d524e1e Sun Feb 16 07:23:13 2025 -0800

View File

@ -0,0 +1 @@
no version in this binary