From 7427445fe98dd72a81835fc0b939912cf270f3a9 Mon Sep 17 00:00:00 2001 From: witchcraze <67056980+witchcraze@users.noreply.github.com> Date: Fri, 20 Jan 2023 01:22:11 +0900 Subject: [PATCH] feat: add memcached classifier (#1486) Signed-off-by: witchcraze --- syft/pkg/cataloger/binary/cataloger_test.go | 17 ++++++++++++++++- .../pkg/cataloger/binary/default_classifiers.go | 8 ++++++++ .../positive/memcached-1.6.18/memcached | 13 +++++++++++++ 3 files changed, 37 insertions(+), 1 deletion(-) create mode 100644 syft/pkg/cataloger/binary/test-fixtures/classifiers/positive/memcached-1.6.18/memcached diff --git a/syft/pkg/cataloger/binary/cataloger_test.go b/syft/pkg/cataloger/binary/cataloger_test.go index 2e86ba2ab8b..412b1aefaef 100644 --- a/syft/pkg/cataloger/binary/cataloger_test.go +++ b/syft/pkg/cataloger/binary/cataloger_test.go @@ -17,6 +17,20 @@ func TestClassifierCataloger_DefaultClassifiers_PositiveCases(t *testing.T) { fixtureDir string expected pkg.Package }{ + { + name: "positive-memcached-1.6.18", + fixtureDir: "test-fixtures/classifiers/positive/memcached-1.6.18", + expected: pkg.Package{ + Name: "memcached", + Version: "1.6.18", + Type: "binary", + PURL: "pkg:generic/memcached@1.6.18", + Locations: singleLocation("memcached"), + Metadata: pkg.BinaryMetadata{ + Classifier: "memcached-binary", + }, + }, + }, { name: "positive-httpd-2.4.54", fixtureDir: "test-fixtures/classifiers/positive/httpd-2.4.54", @@ -30,7 +44,8 @@ func TestClassifierCataloger_DefaultClassifiers_PositiveCases(t *testing.T) { Classifier: "httpd-binary", }, }, - }, { + }, + { name: "positive-php-cli-8.2.1", fixtureDir: "test-fixtures/classifiers/positive/php-cli-8.2.1", expected: pkg.Package{ diff --git a/syft/pkg/cataloger/binary/default_classifiers.go b/syft/pkg/cataloger/binary/default_classifiers.go index 87c836fd6b1..b8f14e8dd81 100644 --- a/syft/pkg/cataloger/binary/default_classifiers.go +++ b/syft/pkg/cataloger/binary/default_classifiers.go @@ -141,4 +141,12 @@ var defaultClassifiers = []classifier{ PURL: mustPURL("pkg:generic/httpd@version"), CPEs: singleCPE("cpe:2.3:a:apache:http_server:*:*:*:*:*:*:*:*"), }, + { + Class: "memcached-binary", + FileGlob: "**/memcached", + EvidenceMatcher: fileContentsVersionMatcher( + `(?m)memcached\s(?P[0-9]+\.[0-9]+\.[0-9]+)`), + Package: "memcached", + PURL: mustPURL("pkg:generic/memcached@version"), + }, } diff --git a/syft/pkg/cataloger/binary/test-fixtures/classifiers/positive/memcached-1.6.18/memcached b/syft/pkg/cataloger/binary/test-fixtures/classifiers/positive/memcached-1.6.18/memcached new file mode 100644 index 00000000000..26304334214 --- /dev/null +++ b/syft/pkg/cataloger/binary/test-fixtures/classifiers/positive/memcached-1.6.18/memcached @@ -0,0 +1,13 @@ +secs_since_last_cmd +listen +memcached 1.6.18 +udp-port +memcached 1.6.18 +Failed to allocate memory +%s,%s +-- +bget +flush_all +VERSION 1.6.18 +quit +BADCLASS invalid class id