Skip to content

Commit

Permalink
Check if PURL is valid before adding it to queries (google#291)
Browse files Browse the repository at this point in the history
This is also probably where having a verbosity level when reporting
could be useful. By default we probably would not want to print out
every invalid PURL, but this could be helpful if someone wants to find
what invalid PURLs they have in their SBOM.
  • Loading branch information
another-rex authored and julieqiu committed May 2, 2023
1 parent 0a8246e commit e619f3a
Showing 1 changed file with 11 additions and 0 deletions.
11 changes: 11 additions & 0 deletions pkg/osvscanner/osvscanner.go
Original file line number Diff line number Diff line change
Expand Up @@ -237,7 +237,14 @@ func scanSBOMFile(r *output.Reporter, query *osv.BatchedQuery, path string) erro
defer file.Close()

count := 0
ignoredCount := 0
err = provider.GetPackages(file, func(id sbom.Identifier) error {
_, err := PURLToPackage(id.PURL)
if err != nil {
ignoredCount++
//nolint:nilerr
return nil
}
purlQuery := osv.MakePURLRequest(id.PURL)
purlQuery.Source = models.SourceInfo{
Path: path,
Expand All @@ -251,6 +258,10 @@ func scanSBOMFile(r *output.Reporter, query *osv.BatchedQuery, path string) erro
if err == nil {
// Found the right format.
r.PrintText(fmt.Sprintf("Scanned %s as %s SBOM and found %d packages\n", path, provider.Name(), count))
if ignoredCount > 0 {
r.PrintText(fmt.Sprintf("Ignored %d packages with invalid PURLs\n", ignoredCount))
}

return nil
}

Expand Down

0 comments on commit e619f3a

Please sign in to comment.