From 7a1a73448aa39e94392367102eabdeb556625304 Mon Sep 17 00:00:00 2001 From: Evan Gibler <20933572+egibs@users.noreply.github.com> Date: Wed, 10 Jul 2024 10:45:24 -0500 Subject: [PATCH] Remove OmitEmpty; fix nil pointer dereference (#351) * Remove OmitEmpty; fix nil pointer dereference Signed-off-by: egibs <20933572+egibs@users.noreply.github.com> * Prevent . being reported for rel path Signed-off-by: egibs <20933572+egibs@users.noreply.github.com> --------- Signed-off-by: egibs <20933572+egibs@users.noreply.github.com> --- bincapz.go | 2 -- pkg/action/scan.go | 13 +++++++------ pkg/bincapz/bincapz.go | 1 - 3 files changed, 7 insertions(+), 9 deletions(-) diff --git a/bincapz.go b/bincapz.go index e45f99911..b40b51022 100644 --- a/bincapz.go +++ b/bincapz.go @@ -69,7 +69,6 @@ func main() { errFirstMissFlag := flag.Bool("err-first-miss", false, "exit with error if scan source has no matching capabilities") errFirstHitFlag := flag.Bool("err-first-hit", false, "exit with error if scan source has matching capabilities") ociFlag := flag.Bool("oci", false, "Scan an OCI image") - omitEmptyFlag := flag.Bool("omit-empty", false, "Omit files that contain no matches") quantityIncreasesRiskFlag := flag.Bool("quantity-increases-risk", true, "increase file risk score based on behavior quantity") profileFlag := flag.Bool("profile", false, "Generate profile and trace files") statsFlag := flag.Bool("stats", false, "Show statistics about the scan") @@ -187,7 +186,6 @@ func main() { MinRisk: minRisk, QuantityIncreasesFisk: *quantityIncreasesRiskFlag, OCI: *ociFlag, - OmitEmpty: *omitEmptyFlag, Renderer: renderer, Rules: yrs, ScanPaths: args, diff --git a/pkg/action/scan.go b/pkg/action/scan.go index 7c15d2cd7..8ee86e1e7 100644 --- a/pkg/action/scan.go +++ b/pkg/action/scan.go @@ -102,8 +102,8 @@ func scanSinglePath(ctx context.Context, c bincapz.Config, yrs *yara.Rules, path fr.Path = fmt.Sprintf("%s ∴ %s", absPath, formatPath(cleanPath)) } - if len(fr.Behaviors) == 0 && c.OmitEmpty { - return nil, nil + if len(fr.Behaviors) == 0 { + return &bincapz.FileReport{Path: path}, nil } return &fr, nil @@ -296,16 +296,17 @@ func processFile(ctx context.Context, c bincapz.Config, yrs *yara.Rules, path st logger.Errorf("scan path: %v", err) return nil, nil } - if fr.Error != "" { - logger.Debugf("scan error: %s", fr.Error) - return nil, nil - } if fr == nil { logger.Infof("%s returned nil result", path) return nil, nil } + if fr.Error != "" { + logger.Errorf("scan error: %s", fr.Error) + return nil, nil + } + if c.Renderer != nil { if fr.RiskScore < c.MinFileRisk { // logger.Infof("%s [%d] does not meet min file risk [%d]", path, fr.RiskScore, c.MinFileRisk) diff --git a/pkg/bincapz/bincapz.go b/pkg/bincapz/bincapz.go index a89ea662c..b99a85397 100644 --- a/pkg/bincapz/bincapz.go +++ b/pkg/bincapz/bincapz.go @@ -24,7 +24,6 @@ type Config struct { MinFileRisk int MinRisk int OCI bool - OmitEmpty bool Output io.Writer Renderer Renderer Rules *yara.Rules