From 26175d74f896aa3579901bc7495de52850524b99 Mon Sep 17 00:00:00 2001 From: witchcraze <67056980+witchcraze@users.noreply.github.com> Date: Fri, 17 Apr 2026 23:38:24 +0900 Subject: [PATCH] fix: consul classifier (#4741) Signed-off-by: witchcraze --- .../binary/classifier_cataloger_test.go | 22 ++++++++++++++++++ syft/pkg/cataloger/binary/classifiers.go | 16 ++++++++++--- .../snippets/consul/1.12.9/linux-amd64/consul | 14 +++++++++++ .../snippets/consul/1.7.14/linux-amd64/consul | Bin 0 -> 351 bytes .../pkg/cataloger/binary/testdata/config.yaml | 14 +++++++++++ 5 files changed, 63 insertions(+), 3 deletions(-) create mode 100644 syft/pkg/cataloger/binary/testdata/classifiers/snippets/consul/1.12.9/linux-amd64/consul create mode 100644 syft/pkg/cataloger/binary/testdata/classifiers/snippets/consul/1.7.14/linux-amd64/consul diff --git a/syft/pkg/cataloger/binary/classifier_cataloger_test.go b/syft/pkg/cataloger/binary/classifier_cataloger_test.go index 2b526f967..6d9e23f1a 100644 --- a/syft/pkg/cataloger/binary/classifier_cataloger_test.go +++ b/syft/pkg/cataloger/binary/classifier_cataloger_test.go @@ -1111,6 +1111,28 @@ func Test_Cataloger_PositiveCases(t *testing.T) { Metadata: metadata("consul-binary"), }, }, + { + logicalFixture: "consul/1.12.9/linux-amd64", + expected: pkg.Package{ + Name: "consul", + Version: "1.12.9", + Type: "binary", + PURL: "pkg:golang/github.com/hashicorp/consul@1.12.9", + Locations: locations("consul"), + Metadata: metadata("consul-binary"), + }, + }, + { + logicalFixture: "consul/1.7.14/linux-amd64", + expected: pkg.Package{ + Name: "consul", + Version: "1.7.14", + Type: "binary", + PURL: "pkg:golang/github.com/hashicorp/consul@1.7.14", + Locations: locations("consul"), + Metadata: metadata("consul-binary"), + }, + }, { logicalFixture: "vault/1.21.0-rc1/linux-amd64", expected: pkg.Package{ diff --git a/syft/pkg/cataloger/binary/classifiers.go b/syft/pkg/cataloger/binary/classifiers.go index c3b7ae15b..e5a3e2f4e 100644 --- a/syft/pkg/cataloger/binary/classifiers.go +++ b/syft/pkg/cataloger/binary/classifiers.go @@ -468,9 +468,19 @@ func DefaultClassifiers() []binutils.Classifier { { Class: "consul-binary", FileGlob: "**/consul", - EvidenceMatcher: m.FileContentsVersionMatcher( - // NOTE: This is brittle and may not work for past or future versions - `CONSUL_VERSION: (?P\d+\.\d+\.\d+)`, + EvidenceMatcher: binutils.MatchAny( + m.FileContentsVersionMatcher( + // NOTE: This is brittle and may not work for past or future versions + `CONSUL_VERSION: (?P\d+\.\d+\.\d+)`, + ), + m.FileContentsVersionMatcher( + // GitDescribe=1.12.9" + `GitDescribe=(?P\d+\.\d+\.\d+)\"`, + ), + m.FileContentsVersionMatcher( + // [NUL][NUL][NUL]v1.7.14[NUL][NUL][NUL] + `\x00+v(?P\d+\.\d+\.\d+)\x00+`, + ), ), Package: "consul", PURL: mustPURL("pkg:golang/github.com/hashicorp/consul@version"), diff --git a/syft/pkg/cataloger/binary/testdata/classifiers/snippets/consul/1.12.9/linux-amd64/consul b/syft/pkg/cataloger/binary/testdata/classifiers/snippets/consul/1.12.9/linux-amd64/consul new file mode 100644 index 000000000..f832c746e --- /dev/null +++ b/syft/pkg/cataloger/binary/testdata/classifiers/snippets/consul/1.12.9/linux-amd64/consul @@ -0,0 +1,14 @@ +name: consul +offset: 52534344 +length: 220 +snippetSha256: ca576f5ee181015359ecf2a2d3b7431593816d510cb1fd03014998128ebfd54c +fileSha256: fc2840fe55664ccc8c197debca3a2f09e907ef0a55cbf3d239d8ea63f66fc96d + +### byte snippet to follow ### + +build -compiler=gc +build -ldflags="-X github.com/hashicorp/consul/version.GitCommit=96505027 -X github.com/hashicorp/consul/version.GitDescribe=1.12.9" +build CGO_ENABLED=0 +build GOARCH=amd64 +build GOOS=linux +build GOAMD \ No newline at end of file diff --git a/syft/pkg/cataloger/binary/testdata/classifiers/snippets/consul/1.7.14/linux-amd64/consul b/syft/pkg/cataloger/binary/testdata/classifiers/snippets/consul/1.7.14/linux-amd64/consul new file mode 100644 index 0000000000000000000000000000000000000000..885afc7d586a0530695a4fbd628b83ed58c4135b GIT binary patch literal 351 zcmYk0OK!t33`EmUT0o}|;9VDiNR#^b8a;s|Q%L~V4q&%MuiX<=P8^`K(BqIpLSy`p zPUmTyKL<6HGRx9w3K+mxqXrp|%c;|VM$O~-a*^fz6p?LRv90vchv={ITQYMMr;pGEZcO}$LIOv5mJ>pD`8yQ<&)+e5|ET33C+!5x5ZroQ+7 ZHT%!MY>C&6>y1^