From 0511972dfaef39a2c904e41d22cda67f779807e5 Mon Sep 17 00:00:00 2001 From: Alex Goodman Date: Fri, 9 Apr 2021 11:41:44 -0400 Subject: [PATCH] clarify default collection value + fix appending conffiles location Signed-off-by: Alex Goodman --- syft/pkg/cataloger/deb/cataloger.go | 4 ++-- syft/pkg/cataloger/deb/parse_dpkg_status.go | 10 ++++------ 2 files changed, 6 insertions(+), 8 deletions(-) diff --git a/syft/pkg/cataloger/deb/cataloger.go b/syft/pkg/cataloger/deb/cataloger.go index 2e54f8698..905d08727 100644 --- a/syft/pkg/cataloger/deb/cataloger.go +++ b/syft/pkg/cataloger/deb/cataloger.go @@ -117,7 +117,7 @@ loopNewFiles: } func getAdditionalFileListing(resolver source.FileResolver, dbLocation source.Location, p *pkg.Package) ([]pkg.DpkgFileRecord, []source.Location) { - // ensure the file list is an empty collection (not nil) + // ensure the default value for a collection is never nil since this may be shown as JSON var files = make([]pkg.DpkgFileRecord, 0) var locations []source.Location @@ -140,7 +140,7 @@ func getAdditionalFileListing(resolver source.FileResolver, dbLocation source.Lo files = append(files, parseDpkgConffileInfo(md5Reader)...) // keep a record of the file where this was discovered - if md5Location != nil { + if conffilesLocation != nil { locations = append(locations, *conffilesLocation) } } diff --git a/syft/pkg/cataloger/deb/parse_dpkg_status.go b/syft/pkg/cataloger/deb/parse_dpkg_status.go index 91f9f0fc5..8992c1836 100644 --- a/syft/pkg/cataloger/deb/parse_dpkg_status.go +++ b/syft/pkg/cataloger/deb/parse_dpkg_status.go @@ -61,7 +61,10 @@ func parseDpkgStatusEntry(reader *bufio.Reader) (pkg.DpkgMetadata, error) { retErr = err } - var entry pkg.DpkgMetadata + entry := pkg.DpkgMetadata{ + // ensure the default value for a collection is never nil since this may be shown as JSON + Files: make([]pkg.DpkgFileRecord, 0), + } err = mapstructure.Decode(dpkgFields, &entry) if err != nil { return pkg.DpkgMetadata{}, err @@ -80,11 +83,6 @@ func parseDpkgStatusEntry(reader *bufio.Reader) (pkg.DpkgMetadata, error) { } } - if entry.Files == nil { - // ensure that the collection is always allocated - entry.Files = make([]pkg.DpkgFileRecord, 0) - } - return entry, retErr }