From 772bbe0d709ccc096ccdad96a5bd01b978bcc194 Mon Sep 17 00:00:00 2001 From: Laurent Goderre Date: Wed, 5 Jun 2024 16:34:33 -0400 Subject: [PATCH] Add classifier for util-linux For distro that don't install it via package manager Signed-off-by: Laurent Goderre --- .../cataloger/binary/classifier_cataloger_test.go | 10 ++++++++++ syft/pkg/cataloger/binary/classifiers.go | 9 +++++++++ .../snippets/util-linux/2.37.4/linux-amd64/getopt | Bin 0 -> 348 bytes .../cataloger/binary/test-fixtures/config.yaml | 8 ++++++++ 4 files changed, 27 insertions(+) create mode 100644 syft/pkg/cataloger/binary/test-fixtures/classifiers/snippets/util-linux/2.37.4/linux-amd64/getopt diff --git a/syft/pkg/cataloger/binary/classifier_cataloger_test.go b/syft/pkg/cataloger/binary/classifier_cataloger_test.go index 7ec368b851f..e0f71998d58 100644 --- a/syft/pkg/cataloger/binary/classifier_cataloger_test.go +++ b/syft/pkg/cataloger/binary/classifier_cataloger_test.go @@ -616,6 +616,16 @@ func Test_Cataloger_PositiveCases(t *testing.T) { Metadata: metadata("busybox-binary", "[", "busybox"), }, }, + { + logicalFixture: `util-linux/2.37.4/linux-amd64`, + expected: pkg.Package{ + Name: "util-linux", + Version: "2.37.4", + PURL: "pkg:generic/util-linux@2.37.4", + Locations: locations("getopt"), + Metadata: metadata("util-linux-binary"), + }, + }, { logicalFixture: "java-jre-openjdk/1.8.0_352-b08/linux-amd64", expected: pkg.Package{ diff --git a/syft/pkg/cataloger/binary/classifiers.go b/syft/pkg/cataloger/binary/classifiers.go index c7ebafa9794..229c513397a 100644 --- a/syft/pkg/cataloger/binary/classifiers.go +++ b/syft/pkg/cataloger/binary/classifiers.go @@ -173,6 +173,15 @@ func DefaultClassifiers() []Classifier { PURL: mustPURL("pkg:generic/busybox@version"), CPEs: singleCPE("cpe:2.3:a:busybox:busybox:*:*:*:*:*:*:*:*"), }, + { + Class: "util-linux-binary", + FileGlob: "**/getopt", + EvidenceMatcher: FileContentsVersionMatcher( + `\x00util-linux\s(?P[0-9]+\.[0-9]+\.[0-9]+)\x00`), + Package: "util-linux", + PURL: mustPURL("pkg:generic/util-linux@version"), + CPEs: singleCPE("cpe:2.3:a:kernel:util-linux:*:*:*:*:*:*:*:*"), + }, { Class: "haproxy-binary", FileGlob: "**/haproxy", diff --git a/syft/pkg/cataloger/binary/test-fixtures/classifiers/snippets/util-linux/2.37.4/linux-amd64/getopt b/syft/pkg/cataloger/binary/test-fixtures/classifiers/snippets/util-linux/2.37.4/linux-amd64/getopt new file mode 100644 index 0000000000000000000000000000000000000000..e27f0695fa6e6387b79bc033c057982018b0894f GIT binary patch literal 348 zcmYL_%WA_g6hyt&S6oQ5bkN(f3HgcARmkG%MXFJ9X-194Sv$n2qp%})XszEf zTI$0fqLq6X4VPX~qn-6g;*!GO7-dW`CbdST20a?9#o!tDLK_rz-{%eOmJK6ZlCC zC)ph<#H~EwSV>1dD$Zdd9UR$Ph4U__wr$Dt1