From ceced5eb27b94df84d60880e6e41a2d42554a628 Mon Sep 17 00:00:00 2001 From: Laurent Goderre Date: Tue, 25 Jun 2024 17:40:40 -0400 Subject: [PATCH] Add detection of Erlang in Alpine linux (#2996) Signed-off-by: Laurent Goderre --- .../binary/classifier_cataloger_test.go | 11 +++++++++++ syft/pkg/cataloger/binary/classifiers.go | 17 +++++++++++++++++ .../cataloger/binary/test-fixtures/config.yaml | 8 ++++++++ 3 files changed, 36 insertions(+) diff --git a/syft/pkg/cataloger/binary/classifier_cataloger_test.go b/syft/pkg/cataloger/binary/classifier_cataloger_test.go index 595bbd0f626..978e457554c 100644 --- a/syft/pkg/cataloger/binary/classifier_cataloger_test.go +++ b/syft/pkg/cataloger/binary/classifier_cataloger_test.go @@ -907,6 +907,17 @@ func Test_Cataloger_PositiveCases(t *testing.T) { Metadata: metadata("erlang-library"), }, }, + { + logicalFixture: "erlang/27.0/linux-amd64", + expected: pkg.Package{ + Name: "erlang", + Version: "27.0", + Type: "binary", + PURL: "pkg:generic/erlang@27.0", + Locations: locations("beam.smp"), + Metadata: metadata("erlang-alpine-binary"), + }, + }, { logicalFixture: "nginx/1.25.1/linux-amd64", expected: pkg.Package{ diff --git a/syft/pkg/cataloger/binary/classifiers.go b/syft/pkg/cataloger/binary/classifiers.go index fb17f0ff260..e11cd2a7fa2 100644 --- a/syft/pkg/cataloger/binary/classifiers.go +++ b/syft/pkg/cataloger/binary/classifiers.go @@ -393,6 +393,23 @@ func DefaultClassifiers() []Classifier { PURL: mustPURL("pkg:generic/erlang@version"), CPEs: singleCPE("cpe:2.3:a:erlang:erlang\\/otp:*:*:*:*:*:*:*:*"), }, + { + Class: "erlang-alpine-binary", + FileGlob: "**/beam.smp", + EvidenceMatcher: evidenceMatchers( + FileContentsVersionMatcher( + // [NUL]/usr/src/otp_src_25.3.2.6/erts/ + `(?m)/src/otp_src_(?P[0-9]+\.[0-9]+(\.[0-9]+){0,2}(-rc[0-9])?)/erts/`, + ), + FileContentsVersionMatcher( + // [NUL]/usr/local/src/otp-25.3.2.7/erts/ + `(?m)/usr/local/src/otp-(?P[0-9]+\.[0-9]+(\.[0-9]+){0,2}(-rc[0-9])?)/erts/`, + ), + ), + Package: "erlang", + PURL: mustPURL("pkg:generic/erlang@version"), + CPEs: singleCPE("cpe:2.3:a:erlang:erlang\\/otp:*:*:*:*:*:*:*:*"), + }, { Class: "erlang-library", FileGlob: "**/liberts_internal.a", diff --git a/syft/pkg/cataloger/binary/test-fixtures/config.yaml b/syft/pkg/cataloger/binary/test-fixtures/config.yaml index 559b36e631c..e14c050c5a3 100644 --- a/syft/pkg/cataloger/binary/test-fixtures/config.yaml +++ b/syft/pkg/cataloger/binary/test-fixtures/config.yaml @@ -63,6 +63,14 @@ from-images: paths: - /usr/local/lib/erlang/erts-14.2.4/lib/internal/liberts_internal.a + - name: erlang + version: 27.0 + images: + - ref: erlang:27.0.0.0-alpine@sha256:82064a65eb1f9901a479d8ada5f622be3bfac8b474dfc876dc00c28fdef4b1b8 + platform: linux/amd64 + paths: + - /usr/local/lib/erlang/erts-15.0/bin/beam.smp + - version: 1.21.3 images: - ref: golang:1.21.3@sha256:3ce8313c3513515040870c55e0c041a2b94f3576a58cfd3948633604214aa811