From db67f16ac6a8a1b880c29b5ef0ac9ec49da5c566 Mon Sep 17 00:00:00 2001 From: Teppei Fukuda Date: Mon, 29 Aug 2022 08:53:13 +0300 Subject: [PATCH] fix: handle empty OS family (#2768) --- .github/workflows/release.yaml | 4 ++-- .github/workflows/test.yaml | 2 +- pkg/scanner/local/scan.go | 13 ++++++++----- 3 files changed, 11 insertions(+), 8 deletions(-) diff --git a/.github/workflows/release.yaml b/.github/workflows/release.yaml index a05b2944442..43a743eb111 100644 --- a/.github/workflows/release.yaml +++ b/.github/workflows/release.yaml @@ -10,7 +10,7 @@ jobs: uses: ./.github/workflows/reusable-release.yaml with: goreleaser_config: goreleaser.yml - goreleaser_options: '--rm-dist --timeout 60m' + goreleaser_options: '--rm-dist --timeout 90m' secrets: inherit deploy-packages: @@ -54,4 +54,4 @@ jobs: run: echo -e "${{ secrets.GPG_KEY }}" | gpg --import - name: Create deb repository - run: ci/deploy-deb.sh \ No newline at end of file + run: ci/deploy-deb.sh diff --git a/.github/workflows/test.yaml b/.github/workflows/test.yaml index 34e9f79d024..a37ede38247 100644 --- a/.github/workflows/test.yaml +++ b/.github/workflows/test.yaml @@ -113,7 +113,7 @@ jobs: uses: goreleaser/goreleaser-action@v3 with: version: v1.4.1 - args: release --snapshot --rm-dist --skip-publish --timeout 60m + args: release --snapshot --rm-dist --skip-publish --timeout 90m build-documents: name: Documentation Test diff --git a/pkg/scanner/local/scan.go b/pkg/scanner/local/scan.go index e3a0d7e9cd2..c40f13c5151 100644 --- a/pkg/scanner/local/scan.go +++ b/pkg/scanner/local/scan.go @@ -80,6 +80,11 @@ func (s Scanner) Scan(ctx context.Context, target, artifactKey string, blobKeys case errors.Is(err, analyzer.ErrUnknownOS): log.Logger.Debug("OS is not detected.") + // Packages may contain OS-independent binary information even though OS is not detected. + if len(artifactDetail.Packages) != 0 { + artifactDetail.OS = &ftypes.OS{Family: "none"} + } + // If OS is not detected and repositories are detected, we'll try to use repositories as OS. if artifactDetail.Repository != nil { log.Logger.Debugf("Package repository: %s %s", artifactDetail.Repository.Family, artifactDetail.Repository.Release) @@ -167,12 +172,10 @@ func (s Scanner) Scan(ctx context.Context, target, artifactKey string, blobKeys } func (s Scanner) osPkgsToResult(target string, detail ftypes.ArtifactDetail, options types.ScanOptions) *types.Result { - if len(detail.Packages) == 0 { + if len(detail.Packages) == 0 || detail.OS == nil { return nil } - if detail.OS != nil { - target = fmt.Sprintf("%s (%s %s)", target, detail.OS.Family, detail.OS.Name) - } + pkgs := detail.Packages if options.ScanRemovedPackages { pkgs = mergePkgs(pkgs, detail.HistoryPackages) @@ -181,7 +184,7 @@ func (s Scanner) osPkgsToResult(target string, detail ftypes.ArtifactDetail, opt return strings.Compare(pkgs[i].Name, pkgs[j].Name) <= 0 }) return &types.Result{ - Target: target, + Target: fmt.Sprintf("%s (%s %s)", target, detail.OS.Family, detail.OS.Name), Class: types.ClassOSPkg, Type: detail.OS.Family, Packages: pkgs,