From 391c994c6aff2d0941535a44674465888d25e2f3 Mon Sep 17 00:00:00 2001 From: Laurent Goderre Date: Thu, 23 May 2024 10:26:04 -0400 Subject: [PATCH] Add haskell binaries cataloger Signed-off-by: Laurent Goderre --- .../binary/classifier_cataloger_test.go | 22 +++++++++++++ syft/pkg/cataloger/binary/classifiers.go | 30 ++++++++++++++++++ .../haskell-ghc/9.6.5/linux-amd64/ghc | Bin 0 -> 353 bytes .../binary/test-fixtures/config.yaml | 16 ++++++++++ 4 files changed, 68 insertions(+) create mode 100644 syft/pkg/cataloger/binary/test-fixtures/classifiers/snippets/haskell-ghc/9.6.5/linux-amd64/ghc diff --git a/syft/pkg/cataloger/binary/classifier_cataloger_test.go b/syft/pkg/cataloger/binary/classifier_cataloger_test.go index 978e457554ce..b47246eac219 100644 --- a/syft/pkg/cataloger/binary/classifier_cataloger_test.go +++ b/syft/pkg/cataloger/binary/classifier_cataloger_test.go @@ -918,6 +918,28 @@ func Test_Cataloger_PositiveCases(t *testing.T) { Metadata: metadata("erlang-alpine-binary"), }, }, + { + logicalFixture: "haskell-ghc/9.6.5/linux-amd64", + expected: pkg.Package{ + Name: "haskell/ghc", + Version: "9.6.5", + Type: "binary", + PURL: "pkg:generic/haskell/ghc@9.6.5", + Locations: locations("ghc-9.6.5"), + Metadata: metadata("haskell-ghc-binary"), + }, + }, + { + logicalFixture: "haskell-cabal/3.10.3.0/linux-amd64", + expected: pkg.Package{ + Name: "haskell/cabal", + Version: "3.10.3.0", + Type: "binary", + PURL: "pkg:generic/haskell/cabal@3.10.3.0", + Locations: locations("cabal"), + Metadata: metadata("haskell-cabal-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 e11cd2a7fa2c..329bc5e73e9d 100644 --- a/syft/pkg/cataloger/binary/classifiers.go +++ b/syft/pkg/cataloger/binary/classifiers.go @@ -427,6 +427,36 @@ func DefaultClassifiers() []Classifier { PURL: mustPURL("pkg:generic/erlang@version"), CPEs: singleCPE("cpe:2.3:a:erlang:erlang\\/otp:*:*:*:*:*:*:*:*"), }, + { + Class: "haskell-ghc-binary", + FileGlob: "**/ghc*", + EvidenceMatcher: FileContentsVersionMatcher( + `(?m)haskell-[^-]*-ghc(?P[0-9]+\.[0-9]+\.[0-9]+)[".]`, + ), + Package: "haskell/ghc", + PURL: mustPURL("pkg:generic/haskell/ghc@version"), + CPEs: singleCPE("cpe:2.3:a:haskell:ghc:*:*:*:*:*:*:*:*"), + }, + { + Class: "haskell-cabal-binary", + FileGlob: "**/cabal", + EvidenceMatcher: FileContentsVersionMatcher( + `(?m)\x00Cabal-(?P[0-9]+\.[0-9]+\.[0-9]+(\.[0-9]+)?)-`, + ), + Package: "haskell/cabal", + PURL: mustPURL("pkg:generic/haskell/cabal@version"), + CPEs: singleCPE("cpe:2.3:a:haskell:cabal:*:*:*:*:*:*:*:*"), + }, + { + Class: "haskell-stack-binary", + FileGlob: "**/stack", + EvidenceMatcher: FileContentsVersionMatcher( + `(?m)Version\s*(?P[0-9]+\.[0-9]+\.[0-9]+),\s*Git`, + ), + Package: "haskell/stack", + PURL: mustPURL("pkg:generic/haskell/stack@version"), + CPEs: singleCPE("cpe:2.3:a:haskell:stack:*:*:*:*:*:*:*:*"), + }, { Class: "consul-binary", FileGlob: "**/consul", diff --git a/syft/pkg/cataloger/binary/test-fixtures/classifiers/snippets/haskell-ghc/9.6.5/linux-amd64/ghc b/syft/pkg/cataloger/binary/test-fixtures/classifiers/snippets/haskell-ghc/9.6.5/linux-amd64/ghc new file mode 100644 index 0000000000000000000000000000000000000000..95976e723d7d68b1ab7a0ea0e8b3a4c91d2fb423 GIT binary patch literal 353 zcmXv}xo*QS4Arc!5RkR86_$M?WD!#f_u zWsLj2agF5*QO0r<2kSfIdOqQNDPx_L|!hbPSfk+O?I5KF>VekOfQ0!3qfxOZvLHeGw zwL0o3p)vw$8FZaJaK78^MEEKw{@xU25wuLx@+m6B_a|0ew$G5}X3T7>+hQNm{A-;} zkPDkqSYb_=+W;BchsWFYDdn