From 8ef44d652dfb262d5a6aa43aaaf93a8dca10e3ba Mon Sep 17 00:00:00 2001 From: Benji Visser Date: Wed, 22 Feb 2023 07:58:05 -0700 Subject: [PATCH] feat: add perl binary classifier (#1592) Signed-off-by: Benji Visser --- syft/pkg/cataloger/binary/cataloger_test.go | 42 ++++++++++++++++++ .../cataloger/binary/default_classifiers.go | 9 ++++ .../classifiers/positive/perl-5.12.5/perl | Bin 0 -> 65 bytes .../classifiers/positive/perl-5.20.0/perl | Bin 0 -> 90 bytes .../classifiers/positive/perl-5.37.8/perl | Bin 0 -> 63 bytes 5 files changed, 51 insertions(+) create mode 100644 syft/pkg/cataloger/binary/test-fixtures/classifiers/positive/perl-5.12.5/perl create mode 100644 syft/pkg/cataloger/binary/test-fixtures/classifiers/positive/perl-5.20.0/perl create mode 100644 syft/pkg/cataloger/binary/test-fixtures/classifiers/positive/perl-5.37.8/perl diff --git a/syft/pkg/cataloger/binary/cataloger_test.go b/syft/pkg/cataloger/binary/cataloger_test.go index 6e916271de7..4e2eb4d0810 100644 --- a/syft/pkg/cataloger/binary/cataloger_test.go +++ b/syft/pkg/cataloger/binary/cataloger_test.go @@ -173,6 +173,48 @@ func Test_Cataloger_DefaultClassifiers_PositiveCases(t *testing.T) { }, }, }, + { + name: "positive-perl-5.12.5", + fixtureDir: "test-fixtures/classifiers/positive/perl-5.12.5", + expected: pkg.Package{ + Name: "perl", + Version: "5.12.5", + Type: "binary", + PURL: "pkg:generic/perl@5.12.5", + Locations: singleLocation("perl"), + Metadata: pkg.BinaryMetadata{ + Classifier: "perl-binary", + }, + }, + }, + { + name: "positive-perl-5.20.0", + fixtureDir: "test-fixtures/classifiers/positive/perl-5.20.0", + expected: pkg.Package{ + Name: "perl", + Version: "5.20.0", + Type: "binary", + PURL: "pkg:generic/perl@5.20.0", + Locations: singleLocation("perl"), + Metadata: pkg.BinaryMetadata{ + Classifier: "perl-binary", + }, + }, + }, + { + name: "positive-perl-5.37.8", + fixtureDir: "test-fixtures/classifiers/positive/perl-5.37.8", + expected: pkg.Package{ + Name: "perl", + Version: "5.37.8", + Type: "binary", + PURL: "pkg:generic/perl@5.37.8", + Locations: singleLocation("perl"), + Metadata: pkg.BinaryMetadata{ + Classifier: "perl-binary", + }, + }, + }, { name: "positive-redis-2.8.23", fixtureDir: "test-fixtures/classifiers/positive/redis-server-2.8.23", diff --git a/syft/pkg/cataloger/binary/default_classifiers.go b/syft/pkg/cataloger/binary/default_classifiers.go index 77e048d9b40..46bf31ca780 100644 --- a/syft/pkg/cataloger/binary/default_classifiers.go +++ b/syft/pkg/cataloger/binary/default_classifiers.go @@ -120,6 +120,15 @@ var defaultClassifiers = []classifier{ Package: "busybox", CPEs: singleCPE("cpe:2.3:a:busybox:busybox:*:*:*:*:*:*:*:*"), }, + { + Class: "perl-binary", + FileGlob: "**/perl", + EvidenceMatcher: fileContentsVersionMatcher( + `(?m)\/usr\/local\/lib\/perl\d\/(?P[0-9]+\.[0-9]+\.[0-9]+)`), + Package: "perl", + PURL: mustPURL("pkg:generic/perl@version"), + CPEs: singleCPE("cpe:2.3:a:perl:perl:*:*:*:*:*:*:*:*"), + }, { Class: "php-cli-binary", FileGlob: "**/php*", diff --git a/syft/pkg/cataloger/binary/test-fixtures/classifiers/positive/perl-5.12.5/perl b/syft/pkg/cataloger/binary/test-fixtures/classifiers/positive/perl-5.12.5/perl new file mode 100644 index 0000000000000000000000000000000000000000..44075881a615d0fc80fdb04d76006015d086c714 GIT binary patch literal 65 zcmdNdEiTf}$xlwq(a*_D(l1CY$}!b9)iX5GGiA_CWzbJaEz?g+(PwZ@%u_E>$S+9E RQvi$QmFDDFDX1260RWol6SM#T literal 0 HcmV?d00001 diff --git a/syft/pkg/cataloger/binary/test-fixtures/classifiers/positive/perl-5.20.0/perl b/syft/pkg/cataloger/binary/test-fixtures/classifiers/positive/perl-5.20.0/perl new file mode 100644 index 0000000000000000000000000000000000000000..9f71e480dbc9b1649ce4e79e55df8056a9a072ae GIT binary patch literal 90 zcmW;CF%Ezr3;;l8U(v-lX^9Dot1m$*hNKiy!1tSY^WkWUTyD?E>B36N4&Aof&6<@A l26{0DG*!!^K0}f^Iz%lQS`SIg>1F9qDhd2q2J-=Pn?5Nh9Si^f literal 0 HcmV?d00001 diff --git a/syft/pkg/cataloger/binary/test-fixtures/classifiers/positive/perl-5.37.8/perl b/syft/pkg/cataloger/binary/test-fixtures/classifiers/positive/perl-5.37.8/perl new file mode 100644 index 0000000000000000000000000000000000000000..ed86dbac148976682e701c0339e648e0d7a3d87f GIT binary patch literal 63 zcmZQ@_wjUcjyKXX(lceyFD)+8&&f|t%+b%uOwun%Ey^*~H`OyX*R#;CurP}^Gtte- S%qy+XP0uUUclHl*