Skip to content

Commit

Permalink
fix: pass on annotations to results
Browse files Browse the repository at this point in the history
  • Loading branch information
another-rex committed Jan 22, 2025
1 parent e35a80c commit 4f55e50
Showing 1 changed file with 20 additions and 5 deletions.
25 changes: 20 additions & 5 deletions pkg/osvscanner/vulnerability_result.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"sort"
"strings"

"github.com/google/osv-scalibr/extractor"
"github.com/google/osv-scanner/internal/grouper"
"github.com/google/osv-scanner/internal/imodels"
"github.com/google/osv-scanner/internal/imodels/results"
Expand All @@ -28,7 +29,13 @@ func buildVulnerabilityResults(
Results: []models.PackageSource{},
ImageMetadata: scanResults.ImageMetadata,
}
groupedBySource := map[models.SourceInfo][]models.PackageVulns{}

type packageVulnsGroup struct {
pvs []models.PackageVulns
annotations []extractor.Annotation
}

groupedBySource := map[models.SourceInfo]*packageVulnsGroup{}
for _, psr := range scanResults.PackageScanResults {
p := psr.PackageInfo
includePackage := actions.ShowAllPackages
Expand Down Expand Up @@ -131,16 +138,24 @@ func buildVulnerabilityResults(
Path: p.Location(),
Type: sourceType,
}
groupedBySource[source] = append(groupedBySource[source], pkg)

if groupedBySource[source] == nil {
groupedBySource[source] = &packageVulnsGroup{}
}

groupedBySource[source].pvs = append(groupedBySource[source].pvs, pkg)
// Overwrite annotations as it should be the same for the same package.
groupedBySource[source].annotations = p.Annotations
}
}

// TODO(v2): Move source analysis out of here.
for source, packages := range groupedBySource {
sourceanalysis.Run(r, source, packages, actions.CallAnalysisStates)
sourceanalysis.Run(r, source, packages.pvs, actions.CallAnalysisStates)
results.Results = append(results.Results, models.PackageSource{
Source: source,
Packages: packages,
Source: source,
ExperimentalAnnotations: packages.annotations,
Packages: packages.pvs,
})
}

Expand Down

0 comments on commit 4f55e50

Please sign in to comment.