From e353214ef8204a2b507f0570b740ca46da1462a6 Mon Sep 17 00:00:00 2001 From: Laurent Goderre Date: Mon, 6 May 2024 11:47:54 -0400 Subject: [PATCH] Add detection for newer version of ErLang/OTP (#2829) Signed-off-by: Laurent Goderre --- .../binary/classifier_cataloger_test.go | 15 +++++++++++-- syft/pkg/cataloger/binary/classifiers.go | 21 ++++++++++++++++-- .../25.3.2.6/linux-amd64/erlexec | Bin .../26.2.0.0/linux-amd64/erlexec | Bin .../26.2.4/linux-amd64/liberts_internal.a | Bin 0 -> 360 bytes .../binary/test-fixtures/config.yaml | 14 ++++++++++-- 6 files changed, 44 insertions(+), 6 deletions(-) rename syft/pkg/cataloger/binary/test-fixtures/classifiers/snippets/{erlexec => erlang}/25.3.2.6/linux-amd64/erlexec (100%) rename syft/pkg/cataloger/binary/test-fixtures/classifiers/snippets/{erlexec => erlang}/26.2.0.0/linux-amd64/erlexec (100%) create mode 100644 syft/pkg/cataloger/binary/test-fixtures/classifiers/snippets/erlang/26.2.4/linux-amd64/liberts_internal.a diff --git a/syft/pkg/cataloger/binary/classifier_cataloger_test.go b/syft/pkg/cataloger/binary/classifier_cataloger_test.go index 680faf08a..64e7074ed 100644 --- a/syft/pkg/cataloger/binary/classifier_cataloger_test.go +++ b/syft/pkg/cataloger/binary/classifier_cataloger_test.go @@ -843,7 +843,7 @@ func Test_Cataloger_PositiveCases(t *testing.T) { }, }, { - logicalFixture: "erlexec/25.3.2.6/linux-amd64", + logicalFixture: "erlang/25.3.2.6/linux-amd64", expected: pkg.Package{ Name: "erlang", Version: "25.3.2.6", @@ -854,7 +854,7 @@ func Test_Cataloger_PositiveCases(t *testing.T) { }, }, { - logicalFixture: "erlexec/26.2.0.0/linux-amd64", + logicalFixture: "erlang/26.2.0.0/linux-amd64", expected: pkg.Package{ Name: "erlang", Version: "26.2", @@ -864,6 +864,17 @@ func Test_Cataloger_PositiveCases(t *testing.T) { Metadata: metadata("erlang-binary"), }, }, + { + logicalFixture: "erlang/26.2.4/linux-amd64", + expected: pkg.Package{ + Name: "erlang", + Version: "26.2.4", + Type: "binary", + PURL: "pkg:generic/erlang@26.2.4", + Locations: locations("liberts_internal.a"), + Metadata: metadata("erlang-library"), + }, + }, { 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 f1be7a6d3..f8cafd828 100644 --- a/syft/pkg/cataloger/binary/classifiers.go +++ b/syft/pkg/cataloger/binary/classifiers.go @@ -361,11 +361,28 @@ func DefaultClassifiers() []Classifier { 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-9]+)?)/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-9]+)?)/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", + 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", diff --git a/syft/pkg/cataloger/binary/test-fixtures/classifiers/snippets/erlexec/25.3.2.6/linux-amd64/erlexec b/syft/pkg/cataloger/binary/test-fixtures/classifiers/snippets/erlang/25.3.2.6/linux-amd64/erlexec similarity index 100% rename from syft/pkg/cataloger/binary/test-fixtures/classifiers/snippets/erlexec/25.3.2.6/linux-amd64/erlexec rename to syft/pkg/cataloger/binary/test-fixtures/classifiers/snippets/erlang/25.3.2.6/linux-amd64/erlexec diff --git a/syft/pkg/cataloger/binary/test-fixtures/classifiers/snippets/erlexec/26.2.0.0/linux-amd64/erlexec b/syft/pkg/cataloger/binary/test-fixtures/classifiers/snippets/erlang/26.2.0.0/linux-amd64/erlexec similarity index 100% rename from syft/pkg/cataloger/binary/test-fixtures/classifiers/snippets/erlexec/26.2.0.0/linux-amd64/erlexec rename to syft/pkg/cataloger/binary/test-fixtures/classifiers/snippets/erlang/26.2.0.0/linux-amd64/erlexec diff --git a/syft/pkg/cataloger/binary/test-fixtures/classifiers/snippets/erlang/26.2.4/linux-amd64/liberts_internal.a b/syft/pkg/cataloger/binary/test-fixtures/classifiers/snippets/erlang/26.2.4/linux-amd64/liberts_internal.a new file mode 100644 index 0000000000000000000000000000000000000000..19276dd389651c421bfc013b56fd3a7fd48c4daf GIT binary patch literal 360 zcma)2Np8d-5X_lZAkE!icKnSz0I_t>Si;7_jFS959woWw)KYgXUA4yz7FyQ?eVk$4 z2lPGGDUybG!dR%~)@V{;zmLa4XTiz2ug3x7{Sk#W3q`OZs-jZK5_rklaOJHPSisI+ zC0~+OS|gt|=X@3pa0b++NG#r?C%9Jl6HDNHOgSgbjW9|&>k>%rj8-v$LA175(2hqT zW7O6=iB9u;c}egF2)W&EG<^-Azi-mfD7ISL2fa=NdJRXva$>;Nw>YN!#-3+qXV0vS kBV02GGl@yDS0(JK=C%7DD7S5E`w#XavU|?#)0tq@HwnIQ!2kdN literal 0 HcmV?d00001 diff --git a/syft/pkg/cataloger/binary/test-fixtures/config.yaml b/syft/pkg/cataloger/binary/test-fixtures/config.yaml index ec0f65808..466f0d40f 100644 --- a/syft/pkg/cataloger/binary/test-fixtures/config.yaml +++ b/syft/pkg/cataloger/binary/test-fixtures/config.yaml @@ -31,20 +31,30 @@ from-images: paths: - /usr/local/bin/gcc - - version: 25.3.2.6 + - name: erlang + version: 25.3.2.6 images: - ref: erlang:25.3.2.6@sha256:0d1e530ec0e8047094f0a1d841754515bad9b0554260a3147fb34df31b3064fe platform: linux/amd64 paths: - /usr/local/lib/erlang/erts-13.2.2.3/bin/erlexec - - version: 26.2.0.0 + - name: erlang + version: 26.2.0.0 images: - ref: erlang:26.2.0.0@sha256:31c3aa505fbe7526ca83c57b64e56ba505e62733e7e6518f4c06219de6e7396e platform: linux/amd64 paths: - /usr/local/lib/erlang/erts-14.2/bin/erlexec + - name: erlang + version: 26.2.4 + images: + - ref: erlang:26.2.4.0@sha256:bdb5bac0612856ec85982171dcd4a11de2e08e7f7469c86f3eb936bdfd1ec204 + platform: linux/amd64 + paths: + - /usr/local/lib/erlang/erts-14.2.4/lib/internal/liberts_internal.a + - version: 1.21.3 images: - ref: golang:1.21.3@sha256:3ce8313c3513515040870c55e0c041a2b94f3576a58cfd3948633604214aa811