From dbc4238f63c027efc09ce5fe51e069c1145f6846 Mon Sep 17 00:00:00 2001 From: Laurent Goderre Date: Tue, 10 Sep 2024 10:58:20 -0400 Subject: [PATCH] Add haskell binaries cataloger (#3078) Signed-off-by: Laurent Goderre --- .../binary/classifier_cataloger_test.go | 22 +++++++++++++ syft/pkg/cataloger/binary/classifiers.go | 30 ++++++++++++++++++ .../haskell-cabal/3.10.3.0/linux-amd64/cabal | Bin 0 -> 350 bytes .../haskell-ghc/9.6.5/linux-amd64/ghc-9.6.5 | Bin 0 -> 353 bytes .../binary/test-fixtures/config.yaml | 16 ++++++++++ 5 files changed, 68 insertions(+) create mode 100644 syft/pkg/cataloger/binary/test-fixtures/classifiers/snippets/haskell-cabal/3.10.3.0/linux-amd64/cabal create mode 100644 syft/pkg/cataloger/binary/test-fixtures/classifiers/snippets/haskell-ghc/9.6.5/linux-amd64/ghc-9.6.5 diff --git a/syft/pkg/cataloger/binary/classifier_cataloger_test.go b/syft/pkg/cataloger/binary/classifier_cataloger_test.go index 4e283a56a..c1bfbb322 100644 --- a/syft/pkg/cataloger/binary/classifier_cataloger_test.go +++ b/syft/pkg/cataloger/binary/classifier_cataloger_test.go @@ -961,6 +961,28 @@ func Test_Cataloger_PositiveCases(t *testing.T) { Metadata: metadata("swipl-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 46afa87f5..5290b4d98 100644 --- a/syft/pkg/cataloger/binary/classifiers.go +++ b/syft/pkg/cataloger/binary/classifiers.go @@ -447,6 +447,36 @@ func DefaultClassifiers() []Classifier { PURL: mustPURL("pkg:generic/swipl@version"), CPEs: singleCPE("cpe:2.3:a:erlang:erlang\\/otp:*:*:*:*:*:*:*:*", cpe.NVDDictionaryLookupSource), }, + { + Class: "haskell-ghc-binary", + FileGlob: "**/ghc*", + EvidenceMatcher: FileContentsVersionMatcher( + `(?m)\x00GHC (?P[0-9]+\.[0-9]+\.[0-9]+)\x00`, + ), + 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-cabal/3.10.3.0/linux-amd64/cabal b/syft/pkg/cataloger/binary/test-fixtures/classifiers/snippets/haskell-cabal/3.10.3.0/linux-amd64/cabal new file mode 100644 index 0000000000000000000000000000000000000000..efc08c38af003803204a2647b785bfd5834dc757 GIT binary patch literal 350 zcmb7?5Loj5kGC4gE(U=`cTxNTf%$<9`e1IP0%Y6~0pd$s|j0U~eo?vyuRC8!`XDTU6G zf;FJmt97fz3?T+XCd@J=K~h+EugL}}HBJHuY|7HkND9pq zYVVYuHgFIbTb6~V&w>2sO+GrOUTgp0vtp$;aUG?e;@W0@EN#EL|K5BtLP=qSyp(p- Vm~ne3=XfjWef+_Qr$+rh;1>r0X=DHZ literal 0 HcmV?d00001 diff --git a/syft/pkg/cataloger/binary/test-fixtures/classifiers/snippets/haskell-ghc/9.6.5/linux-amd64/ghc-9.6.5 b/syft/pkg/cataloger/binary/test-fixtures/classifiers/snippets/haskell-ghc/9.6.5/linux-amd64/ghc-9.6.5 new file mode 100644 index 0000000000000000000000000000000000000000..551b9978c44ce488763aaccc19ff43a019c84c31 GIT binary patch literal 353 zcmXv~v2Mg53}t4h)IUIX%T;O+U?7mSLvQcc35dBwmm{YpQq@oFUzMb-2g}dT@5y!v zH|*GDNR8)~8#?E_;My_S8sn9u6PC+5RICJD%6Pxy`Zfe*Y{$SEXwhMmR_Tm7^&r70 z516FSPGOK9werfx)&)$ihoGgky=avcBGNog_;03_N-0~++GdSL%ie`xbWSaT>#G}} z2*UXc#z2B3LRCZr5usuiC_NsJEPk!X{?=sc%WTR)!5q8Sgvd=d9L_$dOtMNxvsigu@cw_?zrNzsejw`hv$7@#gE&jsl4Wr H+l~JL51U@J 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 ac433555c..58408325b 100644 --- a/syft/pkg/cataloger/binary/test-fixtures/config.yaml +++ b/syft/pkg/cataloger/binary/test-fixtures/config.yaml @@ -78,6 +78,22 @@ from-images: paths: - /usr/lib/swipl/bin/x86_64-linux/swipl + - name: haskell-ghc + version: 9.6.5 + images: + - ref: haskell:9.6.5-slim-buster@sha256:04a7293eb792b82335dffa7f08532657517ed9b4f01d52c1b499ad22deb3c6b1 + platform: linux/amd64 + paths: + - /opt/ghc/9.6.5/lib/ghc-9.6.5/bin/ghc-9.6.5 + + - name: haskell-cabal + version: 3.10.3.0 + images: + - ref: haskell:9.6.5-slim-buster@sha256:04a7293eb792b82335dffa7f08532657517ed9b4f01d52c1b499ad22deb3c6b1 + platform: linux/amd64 + paths: + - /usr/local/bin/cabal + - version: 1.21.3 images: - ref: golang:1.21.3@sha256:3ce8313c3513515040870c55e0c041a2b94f3576a58cfd3948633604214aa811