Skip to content

Commit

Permalink
fix(csaf): products for package names built from the same source
Browse files Browse the repository at this point in the history
RHINENG-9890
  • Loading branch information
psegedy authored and jdobes committed May 28, 2024
1 parent f41f797 commit bb89ec7
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 11 deletions.
5 changes: 3 additions & 2 deletions vmaas/cache.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,9 @@ type Cache struct {

ArchCompat map[ArchID]map[ArchID]bool

PackageDetails map[PkgID]PackageDetail
Nevra2PkgID map[Nevra]PkgID
PackageDetails map[PkgID]PackageDetail
Nevra2PkgID map[Nevra]PkgID
NameID2SrcNameIDs map[NameID]map[NameID]struct{}

RepoIDs []RepoID
RepoDetails map[RepoID]RepoDetail
Expand Down
13 changes: 13 additions & 0 deletions vmaas/load.go
Original file line number Diff line number Diff line change
Expand Up @@ -330,6 +330,7 @@ func loadPkgDetails(c *Cache) {
id2pkdDetail := make(map[PkgID]PackageDetail, cnt)
nevra2id := make(map[Nevra]PkgID, cnt)
srcPkgID2PkgID := make(map[PkgID][]PkgID, cntSrc)
nameID2SrcNameIDs := make(map[NameID]map[NameID]struct{})
var pkgID PkgID
for rows.Next() {
var det PackageDetail
Expand All @@ -347,17 +348,29 @@ func loadPkgDetails(c *Cache) {
continue
}

var srcNameID NameID
row := sqlDB.QueryRow("SELECT name_id FROM package_detail WHERE id = ?", *det.SrcPkgID)
if err := row.Scan(&srcNameID); err != nil {
panic(err)
}
if _, ok := nameID2SrcNameIDs[det.NameID]; !ok {
nameID2SrcNameIDs[det.NameID] = make(map[NameID]struct{})
}
nameID2SrcNameIDs[det.NameID][srcNameID] = struct{}{}

_, ok := srcPkgID2PkgID[*det.SrcPkgID]
if !ok {
srcPkgID2PkgID[*det.SrcPkgID] = []PkgID{}
}

srcPkgID2PkgID[*det.SrcPkgID] = append(srcPkgID2PkgID[*det.SrcPkgID], pkgID)
}

// FIXME: build ModifiedID index (probably not needed for vulnerabilities/updates)
c.PackageDetails = id2pkdDetail
c.Nevra2PkgID = nevra2id
c.SrcPkgID2PkgID = srcPkgID2PkgID
c.NameID2SrcNameIDs = nameID2SrcNameIDs
}

func loadRepoDetails(c *Cache) { //nolint: funlen
Expand Down
26 changes: 17 additions & 9 deletions vmaas/vulnerabilities.go
Original file line number Diff line number Diff line change
Expand Up @@ -389,19 +389,27 @@ func repos2cpes(c *Cache, repoIDs []RepoID) []CpeID {
return res
}

func productsWithCVEs(c *Cache, cpe CpeID, nameID NameID, modules []ModuleStream) []CSAFProduct {
products := make([]CSAFProduct, 0, len(modules)+1)
product := CSAFProduct{CpeID: cpe, PackageNameID: nameID, ModuleStream: ModuleStream{}}
if _, ok := c.CSAFCVEs[product]; ok {
products = append(products, product)
}
for _, ms := range modules {
product = CSAFProduct{CpeID: cpe, PackageNameID: nameID, ModuleStream: ms}
if _, ok := c.CSAFCVEs[product]; ok {
products = append(products, product)
}
}
return products
}

func cpes2products(c *Cache, cpes []CpeID, nameID NameID, modules []ModuleStream, pkg NevraString) ProductsPackage {
products := make([]CSAFProduct, 0, len(cpes)*(len(modules)+1))
for _, cpe := range cpes {
// create unfixed products for every CPE, unfixed product has PackageID=0
product := CSAFProduct{CpeID: cpe, PackageNameID: nameID, ModuleStream: ModuleStream{}}
if _, ok := c.CSAFCVEs[product]; ok {
products = append(products, product)
}
for _, ms := range modules {
product = CSAFProduct{CpeID: cpe, PackageNameID: nameID, ModuleStream: ms}
if _, ok := c.CSAFCVEs[product]; ok {
products = append(products, product)
}
for srcNameID := range c.NameID2SrcNameIDs[nameID] {
products = append(products, productsWithCVEs(c, cpe, srcNameID, modules)...)
}
}
pp := ProductsPackage{}
Expand Down

0 comments on commit bb89ec7

Please sign in to comment.