mirror of
https://github.com/anchore/grype
synced 2024-11-10 06:34:13 +00:00
fix: ask catalog for package rather than type asserting (#1857)
This fixes a class of false positive where removing language packages that are owned by OS packages would incorrectly fail due to a buggy type assertion. --------- Signed-off-by: Will Murphy <will.murphy@anchore.com>
This commit is contained in:
parent
24d5d4ffb2
commit
5ac483a3bc
2 changed files with 21 additions and 8 deletions
|
@ -109,8 +109,8 @@ func removePackagesByOverlap(catalog *pkg.Collection, relationships []artifact.R
|
|||
for p := range catalog.Enumerate() {
|
||||
r, ok := byOverlap[p.ID()]
|
||||
if ok {
|
||||
from, ok := r.From.(pkg.Package)
|
||||
if ok && excludePackage(comprehensiveDistroFeed, p, from) {
|
||||
from := catalog.Package(r.From.ID())
|
||||
if from != nil && excludePackage(comprehensiveDistroFeed, p, *from) {
|
||||
continue
|
||||
}
|
||||
}
|
||||
|
|
|
@ -874,7 +874,7 @@ func catalogWithOverlaps(packages []string, overlaps []string) *sbom.SBOM {
|
|||
pkgs = append(pkgs, p)
|
||||
}
|
||||
|
||||
for _, overlap := range overlaps {
|
||||
for i, overlap := range overlaps {
|
||||
parts := strings.Split(overlap, "->")
|
||||
if len(parts) < 2 {
|
||||
panic("invalid overlap, use -> to specify, e.g.: pkg1->pkg2")
|
||||
|
@ -882,11 +882,24 @@ func catalogWithOverlaps(packages []string, overlaps []string) *sbom.SBOM {
|
|||
from := toPkg(parts[0])
|
||||
to := toPkg(parts[1])
|
||||
|
||||
relationships = append(relationships, artifact.Relationship{
|
||||
From: from,
|
||||
To: to,
|
||||
Type: artifact.OwnershipByFileOverlapRelationship,
|
||||
})
|
||||
// The catalog will type check whether To or From is a pkg.Package or a *pkg.Package.
|
||||
// Previously, there was a bug where Grype assumed that From was always a pkg.Package.
|
||||
// Therefore, intentionally mix pointer and non-pointer packages to prevent Grype from
|
||||
// assuming which is which again. (The correct usage, calling catalog.Package, always
|
||||
// returns a *pkg.Package, and doesn't rely on any type assertion.)
|
||||
if i%2 == 0 {
|
||||
relationships = append(relationships, artifact.Relationship{
|
||||
From: &from,
|
||||
To: &to,
|
||||
Type: artifact.OwnershipByFileOverlapRelationship,
|
||||
})
|
||||
} else {
|
||||
relationships = append(relationships, artifact.Relationship{
|
||||
From: from,
|
||||
To: to,
|
||||
Type: artifact.OwnershipByFileOverlapRelationship,
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
catalog := syftPkg.NewCollection(pkgs...)
|
||||
|
|
Loading…
Reference in a new issue