diff --git a/syft/pkg/cataloger/binary/capabilities.yaml b/syft/pkg/cataloger/binary/capabilities.yaml index 98d7c0f7a..5331d74c9 100644 --- a/syft/pkg/cataloger/binary/capabilities.yaml +++ b/syft/pkg/cataloger/binary/capabilities.yaml @@ -48,7 +48,7 @@ catalogers: type: BinaryPkg - method: glob criteria: - - '**/go' + - '**/{go,go.exe}' packages: - class: go-binary name: go diff --git a/syft/pkg/cataloger/binary/classifier_cataloger_test.go b/syft/pkg/cataloger/binary/classifier_cataloger_test.go index 7eb28706a..587eb3efc 100644 --- a/syft/pkg/cataloger/binary/classifier_cataloger_test.go +++ b/syft/pkg/cataloger/binary/classifier_cataloger_test.go @@ -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). diff --git a/syft/pkg/cataloger/binary/classifiers.go b/syft/pkg/cataloger/binary/classifiers.go index 28e519026..2a0982d96 100644 --- a/syft/pkg/cataloger/binary/classifiers.go +++ b/syft/pkg/cataloger/binary/classifiers.go @@ -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[0-9]+\.[0-9]+(\.[0-9]+|beta[0-9]+|alpha[0-9]+|rc[0-9]+)?)\x00`), + binutils.SupportingEvidenceMatcher("VERSION*", + m.FileContentsVersionMatcher( + `(?m)go(?P[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[0-9]+\.[0-9]+(\.[0-9]+|beta[0-9]+|alpha[0-9]+|rc[0-9]+|-[_0-9a-z]+)?)\s`), - ), + `(?m)go(?P[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"), diff --git a/syft/pkg/cataloger/binary/test-fixtures/classifiers/snippets/go-version-hint/1.15w/any/VERSION b/syft/pkg/cataloger/binary/test-fixtures/classifiers/snippets/go-version-hint/1.15w/any/VERSION new file mode 100644 index 000000000..1c595336d --- /dev/null +++ b/syft/pkg/cataloger/binary/test-fixtures/classifiers/snippets/go-version-hint/1.15w/any/VERSION @@ -0,0 +1 @@ +go1.15 Fri 2003 \ No newline at end of file diff --git a/syft/pkg/cataloger/binary/test-fixtures/classifiers/snippets/go-version-hint/1.15w/any/bin/go.exe b/syft/pkg/cataloger/binary/test-fixtures/classifiers/snippets/go-version-hint/1.15w/any/bin/go.exe new file mode 100644 index 000000000..ae382e1e6 --- /dev/null +++ b/syft/pkg/cataloger/binary/test-fixtures/classifiers/snippets/go-version-hint/1.15w/any/bin/go.exe @@ -0,0 +1 @@ +no version in this binary \ No newline at end of file diff --git a/syft/pkg/cataloger/binary/test-fixtures/classifiers/snippets/go-version-hint/1.21/any/VERSION b/syft/pkg/cataloger/binary/test-fixtures/classifiers/snippets/go-version-hint/1.21/any/VERSION new file mode 100644 index 000000000..32894c1be --- /dev/null +++ b/syft/pkg/cataloger/binary/test-fixtures/classifiers/snippets/go-version-hint/1.21/any/VERSION @@ -0,0 +1 @@ +go1.21 Fri 2003 \ No newline at end of file diff --git a/syft/pkg/cataloger/binary/test-fixtures/classifiers/snippets/go-version-hint/1.21/any/go b/syft/pkg/cataloger/binary/test-fixtures/classifiers/snippets/go-version-hint/1.21/any/go new file mode 100644 index 000000000..ae382e1e6 --- /dev/null +++ b/syft/pkg/cataloger/binary/test-fixtures/classifiers/snippets/go-version-hint/1.21/any/go @@ -0,0 +1 @@ +no version in this binary \ No newline at end of file diff --git a/syft/pkg/cataloger/binary/test-fixtures/classifiers/snippets/go-version-hint/1.25w/any/VERSION b/syft/pkg/cataloger/binary/test-fixtures/classifiers/snippets/go-version-hint/1.25w/any/VERSION new file mode 100644 index 000000000..5ac1e7aad --- /dev/null +++ b/syft/pkg/cataloger/binary/test-fixtures/classifiers/snippets/go-version-hint/1.25w/any/VERSION @@ -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 \ No newline at end of file diff --git a/syft/pkg/cataloger/binary/test-fixtures/classifiers/snippets/go-version-hint/1.25w/any/go.exe b/syft/pkg/cataloger/binary/test-fixtures/classifiers/snippets/go-version-hint/1.25w/any/go.exe new file mode 100644 index 000000000..ae382e1e6 --- /dev/null +++ b/syft/pkg/cataloger/binary/test-fixtures/classifiers/snippets/go-version-hint/1.25w/any/go.exe @@ -0,0 +1 @@ +no version in this binary \ No newline at end of file